Last active
December 20, 2015 06:29
-
-
Save zeroeth/6086045 to your computer and use it in GitHub Desktop.
multiple keypresses in processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Booleans to hold the key states | |
| boolean keyUp,keyDown; | |
| void setup() | |
| { | |
| size (600, 600); | |
| } | |
| // In our loop we check if the booleans have changed | |
| // | |
| void draw () | |
| { | |
| background (0); | |
| if (keyUp) | |
| { | |
| fill (255, 0, 0); | |
| rect (10, 10, width-20, height/2-20); | |
| } | |
| if (keyDown) | |
| { | |
| fill (0, 0, 255); | |
| rect (10, height/2+20, width-20, height/2-20); | |
| } | |
| } | |
| // Fired every time a key is pressed | |
| // | |
| void keyPressed() | |
| { | |
| if (key == 'w') | |
| { | |
| keyUp = true; | |
| } | |
| if (key == 's') | |
| { | |
| keyDown = true; | |
| } | |
| } | |
| // Fired every time a key is released | |
| // | |
| void keyReleased() | |
| { | |
| if (key == 'w') | |
| { | |
| keyUp = false; | |
| } | |
| if (key == 's') | |
| { | |
| keyDown = false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment