How can you find out if...
No, I mean not a specific key. How can you tell if any key is being held?
if(KEYDOWN)?
if(KEYDOWN)?
if(KEYDOWN(''A'') || KEYDOWN(''B'') || KEYDOWN(''C'') ....)
{}
just kidding.
does it need to be asynchronous?
if not, just add getch(); or kbhit(); i forgot which one.
a2k
{}
just kidding.
does it need to be asynchronous?
if not, just add getch(); or kbhit(); i forgot which one.
a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Why not use GetKeyboardState(PBYTE lpKeyState)?
lpKeyState is an array of 256 BYTEs that you allocate and pass to the function. Windows fills this structure with information on each virtual key's status. If the high order bit of the byte is set the key is down, else the key is up.
If I remember correctly you can actually index into the array using the Virtual Key Code identifiers provided by Windows (ex. VK_A, VK_B etc).
Hope this helps you.
- Dire Wolf
direwolf@digitalfiends.com
Edited by - DireWolf on August 21, 2000 10:37:09 PM
lpKeyState is an array of 256 BYTEs that you allocate and pass to the function. Windows fills this structure with information on each virtual key's status. If the high order bit of the byte is set the key is down, else the key is up.
If I remember correctly you can actually index into the array using the Virtual Key Code identifiers provided by Windows (ex. VK_A, VK_B etc).
Hope this helps you.
- Dire Wolf
direwolf@digitalfiends.com
Edited by - DireWolf on August 21, 2000 10:37:09 PM
Okay, this is the way I do it . Learnt it from Nehe.
I have a global array called KeyPressed[256].
Now, whenever there is a WM_KEYDOWN/WM_KEYUP message , I set the KeyPressed[wParam] to True/False.
This way, at any point of time, you have the array KeyPressed[] containing the actual state of any key pressed and so can use it in any statement that''s within the windows message dispatching loop.
Hope this helps.
Neo.
I have a global array called KeyPressed[256].
Now, whenever there is a WM_KEYDOWN/WM_KEYUP message , I set the KeyPressed[wParam] to True/False.
This way, at any point of time, you have the array KeyPressed[] containing the actual state of any key pressed and so can use it in any statement that''s within the windows message dispatching loop.
Hope this helps.
Neo.
Oops!! missed out on a trivia.
How to use it ??
Well, if you want to check for, say, the left arrow key, check to see if KeyPressed[VK_LEFT] is true or false.
You will get all the codes for the keys in "winuser.h "
Neo
How to use it ??
Well, if you want to check for, say, the left arrow key, check to see if KeyPressed[VK_LEFT] is true or false.
You will get all the codes for the keys in "winuser.h "
Neo
''Which one is the ''Any Key''??''
..sorry couldnt resist :D
-DA
..sorry couldnt resist :D
-DA
"You think that''s air your breathing now?"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement