Keyboard input Windows
Usually keyboard events are buffered and then the keyboard state is updated using these. You buffer them the closest as possible to the frame rendering in an attempt to decrease input latency.How do I handle multiple keystrokes in Windows?
No. There is no Win32 documentation stating such thing. If you're holding a key you'll just receive multiple WM_KEYDOWN events.So is this a Windows thing? Should I do it in another way?
I suspect you're processing only one window event per frame. Paste your event loop here please.
IIRC GLFW has a very readable handling of keyboard events. Maybe you check that out if you think that should help.
No. There is no Win32 documentation stating such thing. If you're holding a key you'll just receive multiple WM_KEYDOWN events.
No. When you press a key, a WM_KEYDOWN is sent, and when you release the key, a WM_KEYUP is sent. The WM_KEYPRESSED message repeats during the hold, but it is less useful for game input.
No. When you press a key, a WM_KEYDOWN is sent, and when you release the key, a WM_KEYUP is sent. The WM_KEYPRESSED message repeats during the hold, but it is less useful for game input.
According to the following documentation,
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646280(v=vs.85).aspx
,"Because of the autorepeat feature, more than one WM_KEYDOWN message may be posted before a WM_KEYUP message is posted. The previous key state (bit 30) can be used to determine whether the WM_KEYDOWN message indicates the first down transition or a repeated down transition."
So both options are valid.
Further WM_KEYDOWN messages will only be posted at the auto-repeat rate; there will usually not be a new one in the queue every update.
Additionally, since those messages are tied to the auto-repeat functionality, they will only be sent for the last key pressed, and only as long as that key is held.
You need to handle all messages that are pending and then run your game loop.
Or you need to not clear your list internally every frame.
L. Spiro
Here is my loop.
//messageloop
while (msg.message != WM_QUIT)
{
//send message to windowproc-function
while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
//update
if (!System::Update(Update))
{
//Exit the application on fail
System::Exit(-1);
}
//render
if (!System::Render(Render))
{
//Exit the application on fail
System::Exit(-2);
}
//clear this frames key actions so next one's empty
Input::keysDown.Clear();
Input::keysUp.Clear();
}
Here is the messagehandling:
case WM_KEYDOWN:
Input::keysDown.Add(System::CheckKey(wParam));
return 0;
case WM_KEYUP:
Input::keysUp.Add(System::CheckKey(wParam));
return 0;