Sign in to follow this  
Cygon

How to get WM_KEYUP after losing focus?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1313149814' post='4848178']
The simplest solution is to just mark all keys as released on loss of focus. You can do this by handling WM_ACTIVATE.
[/quote]

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this