Win 32 Keyboard and Mouse Messages


How can I get the key presses when my window is not active or it is Minimized?

The same is the case with the mouse, how can I get it's coordinates when my window is not active?

For keyboard, you can use keyboard hooks. Search for any key logger program that uses keyboard hooks and you will get an idea of how to use them.

For mouse you can capture the mouse using SetCpature Win32 API or CWnd::SetCapture in MFC
This gets the keyboard and mouse key state:

This gets the mouse location:

It's been a while since I've used this, but I believe that you don't even have to have a window open to use those functions. However, I would advise not to use those functions, because some antiviruses pick them up as keyloggers. (My antivirus must be pretty stupid. It didn't catch anything.)

I would use the MSG loop to handle keyboard and mouse inputs; however, I don't believe that those work without focus on your window.
Topic archived. No new replies allowed.