I am having a slight problem when the user Alt+Tabs out of my game (or when another window gets focus somehow): If the user held down a key while this happened, my game will not receive the WM_KEYUP message if the user releases said key again while the window isn't focused.
For the mouse, there's CaptureMouse() (used by Windows' button controls, for example) and TrackMouseEvent().
But I can't find any CaptureKeyboard() or TrackKeyboardEvent() functions. Is there a way, other than polling GetAsyncKeyState()/GetKeyboardState(), to be notified when a key is released again?
How to get WM_KEYUP after losing focus?
The simplest solution is to just mark all keys as released on loss of focus. You can do this by handling WM_ACTIVATE.
The simplest solution is to just mark all keys as released on loss of focus. You can do this by handling WM_ACTIVATE.
Thanks! I would go with the solution in a minute, but I'm not receiving WM_ACTIVATE for some reason.
Some more detail: I'm filtering the messages received by an XNA game via IMessageFilter. This is the same as listening in on the message pump (not on the WndProc()). I expected WM_ACTIVATE (and WM_KILLFOCUS) to pass through the message pump and be sent to the window via DispatchMessage(), but apparently I'm mistaken.
I guess I'll have to install an IMessageFilter *and* subclass the window.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement