Does anyone know why there is some hesitation when you hold down a keyboard key and try to process it? I'm calling a function right in my WinProc(...) that will move an image on the screen (OpenGL) when a key is held down. I press it and get a single response, then there is about .5 seconds of nothing, then it behaves as normal (moves 1 pixel every WinMain loop).
I'm wondering if the Windows messages are being delayed somehow because of some feature I need to disable???
Here's my code:
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd)
{
bool quit = false;
MSG msg;
createWindow(hinstance, SCRW, SCRH, SCRD, WINDOWED);
// Main loop
while (!quit)
{
if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
{
if (msg.message == WM_QUIT)
quit = true;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
renderFrame(); // processes graphics
SwapBuffers(hdc);
}
return msg.lParam;
}
and WinProc (there were more cases but same thing...):
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_KEYDOWN:
switch ( wparam )
{
case VK_RIGHT:
key_RIGHT();
return 0;
}
return 0;
}
}
and key_RIGHT:
void key_RIGHT()
{
MoveObjectRight1Pixel();
}