Last active
August 29, 2015 13:59
-
-
Save falkirks/10937029 to your computer and use it in GitHub Desktop.
Check for multiple key presses in Java 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
class bindKey { | |
IntList keylist; | |
public bindKey() { | |
keylist = new IntList(); | |
} | |
public void pressKey(int key) { | |
if (!keylist.hasValue(key)) keylist.append(key); | |
} | |
public void releaseKey(int key) { | |
if (keylist.hasValue(key)) { | |
for (int i = 0; i < keylist.size(); i++) { | |
if (keylist.get(i) == key) { | |
keylist.remove(i); | |
return; | |
} | |
} | |
} | |
} | |
public Boolean isPressed(int check){ | |
return keylist.hasValue(check); | |
} | |
} |
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
bindKey keys; | |
void setup(){ | |
size(800,600); | |
keys = new bindKey(); | |
} | |
void draw(){ | |
if(keys.isPressed(UP) && keys.isPressed(DOWN)) background(0); | |
else background(255); | |
} | |
void keyPressed(KeyEvent evt){ | |
keys.pressKey(evt.getKeyCode()); | |
} | |
void keyReleased(KeyEvent evt){ | |
keys.releaseKey(evt.getKeyCode()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment