getting two keys from keyboard simultaneously
-
HI I want to get two keys from the keyboard simultaneously , I mean when you press and hold two keys the kbhit() and getch() functions return only the first pressed key . thanks
V_shr wrote:
I want to get two keys from the keyboard simultaneously
This is impossible since the link from the keyboard is serial. The only way to detect if two keys are pressed simultaniously is if one of them is a shift-key or similar since that would have an impact on the scan code.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
V_shr wrote:
I want to get two keys from the keyboard simultaneously
This is impossible since the link from the keyboard is serial. The only way to detect if two keys are pressed simultaniously is if one of them is a shift-key or similar since that would have an impact on the scan code.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknownThat is incorrect. The GetAsyncKeyState() function will return the status of any key on the keyboard, up or down. You can use this macro:
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
to determine if a key is currently being pressed. This will check key state even if your application does not have focus. If you are actually wanting to capture the key presses, you would actually have loop through all of the key codes and check individual status with this method. Dustin -
That is incorrect. The GetAsyncKeyState() function will return the status of any key on the keyboard, up or down. You can use this macro:
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
to determine if a key is currently being pressed. This will check key state even if your application does not have focus. If you are actually wanting to capture the key presses, you would actually have loop through all of the key codes and check individual status with this method. DustinDustin Henry wrote:
That is incorrect.
What is incorrect? Whether the link to the keyboard is serial or not isn't a matter of opinion. I guess I misinterpreted the OP's problem and what he meant with "simultaneously". If the question is "how can I determine what keys are being held down", then the answer is "poll the keys with
::GetAsyncKeyState()
", like you suggested.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown