I am designing a keyboard class that can detect the keyboard key press only one time but I still cannot figure out the way to do it. My goal is just check and perform the action
Bit 30 of the lParam
value for the WM_KEYDOWN message indicates whether or not the key was previously down when the message was generated. You can use this to distinguish between the actual keypress and any subsequent key repeats.
case WM_KEYDOWN:
if (lParam & (1 << 30))
{
// this is a repeat
}
else
{
// first press
}
break;
But if, as it seems, you're trying to check in realtime which keys are down, you can do this using the GetAsyncKeyState() function rather than relying on tracking keystate via your message loop.