How to switch from one control to another using the tabulator key in controlP5 from processing?

203 Views Asked by At

I am doing a GUI on processing and using controlP5. I would like to use my keyboard to switch between controls but I failed miserably.

Another thing I would like to do is remove the cursor from the TextAreas since always is a character behind instead of beeing at the end.

Have someone a clue of how to achive that? I would be really happy if someone with bigger knowledge knows how to, I am really getting monkey!

Thanks

1

There are 1 best solutions below

7
Jose On

Well, I did figure it out in my own. These ControlP5 are not really intuitive controls. There is not documentation at all, and the most common features in controls like this one (usability) are not covered in the examples. A pity. Anyways, here it is:

import java.awt.event.KeyEvent;
import controlP5.*;

ControlP5 cp5;

boolean isTabPressed = false;

void keyPressed()
{
      if(keyCode== TAB){
          isTabPressed = !isTabPressed;

         if(isTabPressed){
           Textfield tf = (Textfield) cp5.getController("textValue");
           tf.setFocus(true);
           Textfield tf1 = (Textfield) cp5.getController("textValue1");
           tf1.setFocus(false);
          }else{   
           Textfield tf = (Textfield) cp5.getController("textValue");
           tf.setFocus(false);
           Textfield tf1 = (Textfield) cp5.getController("textValue1");
           tf1.setFocus(true);
         }
     }
            
}

void setup()
{
    size(400,180);
    
    cp5 = new ControlP5(this);

    cp5.addTextfield("textValue")
     .setPosition(100, 30)
     .setSize(200, 20)
     .setAutoClear(false)
     ;
     
    cp5.addTextfield("textValue1")
     .setPosition(100, 90)
     .setSize(200, 20)
     .setAutoClear(false)
     ;
     

}

void draw()
{

}