|
Author |
Topic: detecting multiple keypresses/releases (Read 1157 times) |
|
elbucanero
|
detecting multiple keypresses/releases
« on: Apr 21st, 2004, 11:53am » |
|
hey all, new to this forum, so far i've done a little processing and i'm now looking at it in the hope of finding a way to detect more than one keypress and release. So if i press "A" and "S" at the same time and after that release only "S" i'd like to know that S is released and A is still pressed. Anyone know how to do this? Or else an easy program with audio possibilities that can do this? Thanks a lot, Tim
|
|
|
|
fry
|
Re: detecting multiple keypresses/releases
« Reply #1 on: Apr 21st, 2004, 1:32pm » |
|
just use: void keyPressed() { } void keyReleased() { } which will be called as the key is pressed or released. if you need an easy way to keep track, use: boolean pressed[] = new boolean[128]; void keyPressed() { pressed[key & 0x7f] = true; // the &0x7f just means to only allow numbers < 128 /* then you can do things like if (pressed['S']) { println("blah!"); } */ } void keyReleased() { pressed[key & 0x7f] = false; }
|
|
|
|
elbucanero
|
Re: detecting multiple keypresses/releases
« Reply #2 on: Apr 21st, 2004, 4:01pm » |
|
Thanks! It works like a charm!
|
|
|
|
elbucanero
|
Re: detecting multiple keypresses/releases
« Reply #3 on: Apr 21st, 2004, 6:29pm » |
|
Hmm not so charming afterall. It only detects a maximum of 2 keys at once. I want to use a total of 14 keys actually, though not all will be pressed at the same time. An amount of 4 or 5 would be enough. Is this possible? Thanks, Tim
|
|
|
|
toxi_ Guest
|
Re: detecting multiple keypresses/releases
« Reply #4 on: Apr 21st, 2004, 7:24pm » |
|
that will most likely be a hardware issue as there're not many keyboards around which will manage more than 3 keys (excluding modifier keys like shift/ctrl/alt). most of the cheaper keyboards will only manage 2 keys... i believe it has to do with the internal wiring of the keyboard matrix.
|
|
|
|
elbucanero
|
Re: detecting multiple keypresses/releases
« Reply #5 on: Apr 21st, 2004, 9:41pm » |
|
my 17 inch 1,33 ghz powerbook has a cheap keyboard? i feel dirty. hehe
|
|
|
|
toxi_ Guest
|
Re: detecting multiple keypresses/releases
« Reply #6 on: Apr 22nd, 2004, 12:52pm » |
|
well, if it hurts too much, just think about it from that point of view: your keyboard isn't necessarily cheap. why would a keyboard need to register more than 2-3 keys at all? keyboards still are made (to 99%) for typing text and even the fastest typer won't hit more than that 2-3 keylimit at once... sadly, it's all down to economics, even in "branded" products... also check diz
|
|
|
|
elbucanero
|
Re: detecting multiple keypresses/releases
« Reply #7 on: Apr 23rd, 2004, 11:53am » |
|
I modified the code a bit, now it checks if a key is toggled, not just pressed. This works great keyboard wise, no problems with keyjamming. Cool
|
|
|
|
|