Part of the code:
LRESULT CALLBACK WindowProc(
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam)
{ ...
switch(uMsg)
{ ...
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_KEYUP:
{
uint8_t VKCODE = wParam;
bool WasDown = ((lParam & (1<<30)) != 0);
bool IsDown = ((lParam & (1<<31)) == 0);
if(WasDown != IsDown)
{
if(VKCode == 'W')
{
OutputDebugStringA("W: ");
if(WasDown)
{
OutputDebugStringA("WasDown ");
}
if(IsDown)
{
OutputDebugStringA("IsDown ");
}
OutputDebugStringA("\n");
}
else if(VKCode == 'A')
{
OutputDebugStringA("A\n");
}
...
}
} break;
...
}
...
}
1) First, when I press 'A', will always output 2 'A's.
2) Second, according to this page: https://learn.microsoft.com/en-us/windows/desktop/inputdev/wm-keyup
30 The previous key state. The value is always 1 for a WM_KEYUP message.
31 The transition state. The value is always 1 for a WM_KEYUP message.
then (lParam & (1<<31)) will always be non-zero, so IsDown will always be false, but when I press(hit and release) 'W' it will output:
IsDown
WasDown
How come it will output "IsDown" if bool IsDown is always false?
3) If I comment out 3 cases before WM_KEYUP like this:
// case WM_SYSKEYDOWN:
// case WM_SYSKEYUP:
// case WM_KEYDOWN:
then when I press 'A' will only output one 'A', when I press 'W' will only output "WasDown", never "IsDown". I didn't wrote any code under previous 3 cases before comment them out anyway, what happened?
BTW, I'm following this video if anyone wants to see the full code: