detecting when a key is pressed!
Page 1 of 14 Replies - 27377 Views - Last Post: 20 July 2010 - 08:52 AM
#1 Guest_lochness*
detecting when a key is pressed!
Posted 19 July 2010 - 06:56 PM
anyone know what function i can use from the windows api to tell if a key on the keyboard has been pressed
? im pretty much wanting to count how many keys are pressed in a minute?? -thx
Replies To: detecting when a key is pressed!
#2
Re: detecting when a key is pressed!
Posted 19 July 2010 - 07:00 PM
Check out the family of keyboard input functions. What you need will depend on whether or not you want to check specific keys, any key presses, etc...
#3 Guest_lochness*
Re: detecting when a key is pressed!
Posted 19 July 2010 - 07:10 PM
im assuming i would use WM_KEYDOWN and WM_KEYUP but still unsure of how to use this? it's not a function so im a little lost!
#4
Re: detecting when a key is pressed!
Posted 20 July 2010 - 03:16 AM
LRESULT CALLBACK WindowProc
(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//window stuff such as buttons
switch (message)
{
case: WM_KEYDOWN
// do something
case: WM_KEYUP
// do something
}
return DefWindowProc (hwnd,message,wParam,lParam);
}
Im assumming its a Win32 project your working on you dont say in your post ??
You dont say much in your post mind you ??
#5
Re: detecting when a key is pressed!
Posted 20 July 2010 - 08:52 AM
You could use GetAsyncKeyState(), but this is not always the best solution. If you are using the windows API, a good method would be to have a global array of virtual keys, for example.
Then when you detect a key press you can set the correct state of the key that is pressed, for example.
Then you can simply check for a key press like so.
bool keys[256];
Then when you detect a key press you can set the correct state of the key that is pressed, for example.
switch (message)
{
case: WM_KEYDOWN
keys[wParam] = true; // wParam holds the key pressed/released
break;
case: WM_KEYUP
keys[wParam] = false;
break;
}
Then you can simply check for a key press like so.
if (keys[keyCode])
{
// do something
keys[keyCode] = false; // prevent from repeating the detection of the key
}
This post has been edited by Aphex19: 20 July 2010 - 08:54 AM
Page 1 of 1

New Topic/Question
Reply
MultiQuote





|