We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › all keys in the keyboard for programs, how
Page Index Toggle Pages: 1
all keys in the keyboard for programs, how? (Read 1183 times)
all keys in the keyboard for programs, how?
Jun 16th, 2005, 6:56am
 
I forgot where I saw it but there was some way of translating the rare keys values to numbers and use them, like ESC equals to /136 or something like that. Even if I get to do that, how can I upstand against the fact that the systme variable Key only saves one key pressed?, in fact I need to save at least 3 or four keys, and they must be also rare ones like I was asking up. I made an array which is being actualized by the keys pressed but is there any other way for doing it?
How does the keyEvent works?
Re:  all keys in the keyboard for programs, h
Reply #1 - Jun 16th, 2005, 9:32am
 
int(key)?
Re:  all keys in the keyboard for programs, h
Reply #2 - Jun 16th, 2005, 11:50am
 
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?)
}
}
}
Re:  all keys in the keyboard for programs, h
Reply #3 - Jun 22nd, 2005, 7:29pm
 
man, thats all the information I needed, only hope it works on the alpha version cause im using the midi library which is only for the alpha version. Thanks a lot!!!
Page Index Toggle Pages: 1