|
Prevent user from pressing more than one key |
Gia Nguyen
Member #6,912
February 2006
|
Hi there, How do I prevent the user from holding down more than one key simultaneously? Cheers, |
X-G
Member #856
December 2000
|
Some kind of electrocuting element in his keyboard? -- |
miran
Member #2,407
June 2002
|
You can't. Unless you go over to each user and cut off nine of their fingers. And even then they might be able to press two adjacent keys simultaneously with the one remaining finger. -- |
Gia Nguyen
Member #6,912
February 2006
|
, happy Monday ... extern int (*keyboard_callback)(int key); If set, this function is called by the keyboard handler in response to every keypress. It is passed a copy of the value that is about to be added into the input buffer, and can either return this value unchanged, return zero to cause the key to be ignored, or return a modified value to change what readkey() will later return. Allow me to try again, I'm asking about this function above. Is there an example of how this can be used to ignore certain keys, or process each key sequentially if more than one are pressed at the same time? |
FMC
Member #4,431
March 2004
|
I don't know if it is the case but usually you can do: in this way you only react to ONE keypress. [FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites] |
miran
Member #2,407
June 2002
|
Quote: Allow me to try again, I'm asking about this function above. Is there an example of how this can be used to ignore certain keys, or process each key sequentially if more than one are pressed at the same time? What exactly are you trying to do? If you're trying to fix your football game, you're going about it the wrong way. Just use the key[] array as FMC said and organize your code better... -- |
Gia Nguyen
Member #6,912
February 2006
|
if(key[KEY_SPACE])do_stuff(); Yes, but if the user holds the Up key and the Right key at the same time, you get diagonal movement instead of Up, then Right, or Right and Up. I've tried Rest(), may be set keyboard instead? |
miran
Member #2,407
June 2002
|
Quote: Yes, but if the user holds the Up key and the Right key at the same time, you get diagonal movement instead of Up, then Right, or Right and Up. No. Notice the elses. Quote: I've tried Rest(), may be set keyboard instead? No. -- |
Gia Nguyen
Member #6,912
February 2006
|
Ok, thank you very much, that helps! I appreciate it ... |
CGamesPlay
Member #2,559
July 2002
|
does help. I'll say the same thing with different words: The "else" means that only ONE of those actions will happen, the rest will be skipped. -- Ryan Patterson - <http://cgamesplay.com/> |
FMC
Member #4,431
March 2004
|
Quote: Yes, but if the user holds the Up key and the Right key at the same time, you get diagonal movement instead of Up, then Right, or Right and Up. I've tried Try out this code:
[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites] |
Gia Nguyen
Member #6,912
February 2006
|
Yep, it was so obvious, it must be Monday . Thx again, FMC, Miran, CGamesPlay. |
|