Lavit, we were discussing something similar in this topic:
Entitled: keysPressed[] idea
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_Responsive;action=display;num=1117955653
blueNinja suggested that the char datatype contains the same values as key. So if you can type q key on the keyboard you may be able to do a comparison against it.
e.g.:
if(key == '@') {
...
}
If you look at KeyEvent int he Java API:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html
There is along list of static variables for different keys.
e.g.
if(key == KeyEvent.VK_ESCAPE) {
println("Someone pressed Escape");
}
You could write your own key handling event in your own libary, or somewhere. E.g. I quickly wrote this - once the applet has focus it will print the keyChar, keyCode and quite usefully the keyText (very descriptive) to the console log.
Code:keyLib kl;
void setup() {
kl = new keyLib(this);
}
void draw() {
}
public class keyLib {
keyLib(PApplet parent) {
parent.registerKeyEvent(this);
}
public void keyEvent(KeyEvent e) {
char ch = e.getKeyChar();
int kc = e.getKeyCode();
String kt = e.getKeyText(kc);
if(e.getID() == KeyEvent.KEY_PRESSED) {
//... Key Pressed
} else
if(e.getID() == KeyEvent.KEY_RELEASED) {
//... Key Released
println("The key "+ch+"("+kc+", "+kt+") was typed");
} else
if(e.getID() == KeyEvent.KEY_TYPED) {
//... Key Typed (ascii characters only?)
}
}
}