Answer the question
In order to leave comments, you need to log in
How to catch pressing of two WinApi keys?
Hello.
I can not catch up with how to catch pressing two keys at the same time. I need the action to be performed exactly NOT when two of these keys are pressed, and if one key is pressed, then perform such and such an action and if the second one still add another action to this action. Though it is possible and when these two keys are clamped. No difference. Tried from some other experience like this:
LRESULT CALLBACK UpdateMessagesWindow(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_KEYDOWN:
CheckPressKey(wParam);
break;
}
}
void CheckPressKey(keyid)
{
if(keyid & 0x41) // A
{
}
if(keyid & 0x57) // W
{
}
}
Answer the question
In order to leave comments, you need to log in
the code in the check is executed by pressing absolutely any key, and not by "A" and "W". How to be?
if(keyid & 0x41)
, you have to write if(keyid == 0x41)
.
There are also two events: WM_KEYDOWN and WM_KEYUP.
You need to store two flags: is_A_pressed, is_B_pressed.
void handleKeyDown(keyid)
{
if(keyid & 0x41) // A
{
is_A_pressed = true;
}
if(keyid & 0x57) // W
{
is_W_pressed = true;
}
if (is_A_pressed && is_W_pressed) {
// обе клавиши нажаты
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question