Skip to content

Instantly share code, notes, and snippets.

@michaelbartnett
Created March 29, 2012 00:44
Show Gist options
  • Save michaelbartnett/2231925 to your computer and use it in GitHub Desktop.
Save michaelbartnett/2231925 to your computer and use it in GitHub Desktop.
Boilerplate to get some slightly more useful keyboard input functions in Processing
import java.util.HashMap;
HashMap<Integer, Boolean> CodedKeys = new HashMap<Integer, Boolean>();
HashMap<Character, Boolean> CharKeys = new HashMap<Character, Boolean>();
void keyPressed() {
if (key == CODED) {
CodedKeys.put(keyCode, true);
} else {
CharKeys.put(key, true);
}
}
void keyReleased() {
if (key == CODED) {
CodedKeys.put(keyCode, false);
} else {
CharKeys.put(key, false);
}
}
boolean isKeyDown(char the_key) {
Boolean result = CharKeys.get(the_key);
return result != null ? result : false;
}
boolean isKeyDown(int the_key) {
Boolean result = CodedKeys.get(the_key);
return result != null ? result : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment