So I'm writing a game engine and I've been struggling with getting a
key input system working that works on all devices properly.
Right now I'm using GxOpenInput() to disable key filtering at the
start of my app and GxCloseInput() at the end of the app. I capture
key input in the message procedure via WM_KEYDOWN and WM_KEYUP
messages and then set a member variable based on that.
For example:
LRESULT TApplication::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
case WM_KEYDOWN:
switch (wParam)
{
case VK_TACTION:
m_dwKeyInput |= ACTION;
return 0L;
}
break;
case WM_KEYUP:
{
case VK_TACTION:
m_dwKeyInput &= ~ACTION;
return 0L;
}
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
That's a very reduced version for brevity but it captures all the
important keys - UP, DOWN, LEFT, RIGHT, ACTION, SOFT 1 & 2, HOME,
BACK, TALK and END.
This sytem works very well across all devices BUT there are some
exceptions. For instance, on most devices pressing the ENDCALL button
will generate a WM_KEYDOWN message and then WM_KEYUP when the button
is released. But on some devices (like the Samsung Blackjack) pressing
the ENDCALL generates both WM_KEYDOWN and a WM_KEYUP messages one
after the other which of course leads to the m_dwKeyInput being set
and cleared before it can ever be used in the game loop.
Does anyone have any insight on this? Would be greatly appreciated!
Fred