handle mouse event on the screen outside the program

garink
garink used Ask the Experts™
on
Hi all,

I got a problem about handling mouse and keyboard event...

I want to catch the mouse and keyboard event outside the program..

suppose I got my program running in background and I want to catch the mouse event while working with
other program, how can I do that?

thanks in advance

I got this similar question in java section...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Im assuming this post regards Windows.
Im new around here and I don't mean to complain but I've noticed that *alot* of questions in the C++ forum is strictly MS Windows specific!

Whats the deal with that? are they not aware of the fact that there is a Platform->Win Prog forum as well?
Installing a Hook will be the most current (and probably the only) answer you will get : )
The keywords are SetWindowsHookEx and WH_MOUSE
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Commented:
In order to capture system-wide mouse and keyboard input, you will need to install two system-wide hooks. One would be a WH_MOUSE hook, and the other will be a WH_KEYBOARD hook.

Windows requires that all system-wide hooks be installed from a dll.

If you have never done this before, worry not. It's not as difficult as it sounds.

The sample I'm referring you to, uses both a keyboard as well as a mouse hook from a dll to determine the system idle time on Windows 9x. So essentially, your problem is already solved:

http://www.microsoft.com/msj/0200/c/c0200.aspx

Commented:
Now when I think about it, You have to look up "hooks" in your win32 API reference.
Im also pretty sure that you can't grab key and mouse from outside your program without linking the key-grab function of yours to a DLL file.

Commented:
Whops, sorry I had my webbrowser open to this page the entire time and i didn't see that people already had answered.
My bad.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: knightmad {http:#9247842}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial