We are about to switch to a new forum software. Until then we have removed the registration on this forum.
how can i use keypressed to press a specific key like "s"
You would have to press the key yourself, but the variable key always stores the last key that has been pressed. Example:
key
void draw(){} void keyPressed(){ if(key == 's'){ println("'s' pressed"); } }
If you're only interested in knowing whether the 'S' key was pressed, use keyCode:
void keyPressed() { final k = keyCode; if (k == 'S') println("Either 'S' or 's' was pressed"); }
However, if you need to distinguish the lower & upper cases, use key instead:
void keyPressed() { if (key == 'S') println('S'); else if (key == 's') println('s'); }
Answers
You would have to press the key yourself, but the variable
key
always stores the last key that has been pressed. Example:If you're only interested in knowing whether the 'S' key was pressed, use keyCode:
However, if you need to distinguish the lower & upper cases, use key instead: