Sign in to follow this  

Get KeyStrokes & Mouse without Focus

This topic is 2834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I am trying to figure out how to capture the keystrokes & mouse with my Win32 C++ program when the application doesn't have the focus or the app is minimised. I have tried WM_SYSKEYDOWN etc, but I know this doesn't work?

Share this post


Link to post
Share on other sites
You get no messages (well, not keyboard and mouse, anyway) if you don't have the focus.

If you absolutely need to get to those events, you can install a hook procedure, which is kind of intrusive, and not precisely pretty. Look up SetWindowsHookEx for that. Note that this may cause your program to be flagged as spyware by some antivirus software.

Or, you can use raw input. I've used raw input to read 6dof devices such as space navigator, and it works fine even if the application does not have the focus. I see no reason why it should in principle not work for the mouse or the keyboard identically.
The problem with raw input is that it is, well, raw. That means you lose all configurable and localisable features (ballistics, repeat, keymap) that Windows adds upon these raw messages, you need to do all that yourself, and in the case of keypresses, this will be very painful.

Share this post


Link to post
Share on other sites
Why do you want to capture input when the app is minimized?

Generally users expect minimized apps and ones without focus not to respond to the mouse or keyboard. If you've just lost focus I think you should still get mouse events when the mouse is over your window though.

There is one standard Windows API for registering global hotkeys that you might find useful, depending on what you're trying to do: RegisterHotKey().

Share this post


Link to post
Share on other sites

This topic is 2834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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