Created
March 29, 2012 00:44
-
-
Save michaelbartnett/2231925 to your computer and use it in GitHub Desktop.
Boilerplate to get some slightly more useful keyboard input functions in Processing
This file contains 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
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