Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Hooks for Detecting Global Mouse and Keyboard Movement

Posted on 1997-06-17
4
Medium Priority
?
475 Views
Last Modified: 2008-03-17
I need to write a program which detects Mouse Movement and Keyboard Input.  Currently I'm trying to use HOOKS to accomplish this.  
As it stands my program only works within my program window.
For example, I have my program display a message box everytime I click the left mouse button.  However, when
I click the left mouse button outside the program window or anywhere on the desktop nothing happens.  No message box
is displayed even though I clicked on the mouse button.

I'm using      "if (wParam == WM_LBUTTONDOWN)"
to detect the left mouse button, but it's not global.  Meaning it
only works on one window.  
My question is how do I write a C++ program which detects
Mouse Movement and Keyboard Input anywhere, on any window on the desktop?  Thanks.
   
0
Comment
Question by:vjean
  • 2
  • 2
4 Comments
 

Author Comment

by:vjean
ID: 1163960
Edited text of question
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1163961
1. The system hook function must be in a DLL.
2. HOOKPROC hkprcSysMsg;
   static HINSTANCE hinstDLL;
   static HHOOK hhookSysMsg;

   ...

   hinstDLL = ::LoadLibrary("c:\\windows\\your.dll");
   hkprcSysMsg = (HOOKPROC)::GetProcAddress(hinstDLL, "MouseProc");
   hhookSysMsg = ::SetWindowsHookEx(WH_MOUSE,
    hkprcSysMsg, hinstDLL, 0);  // 0 means the hook procedure is associated with all existing threads.

For more information, see Win32 SDK documentation about Hooks.
0
 

Author Comment

by:vjean
ID: 1163962
What exactly do I put into "my.dll"?
The Mouse Procedure or something?

0
 
LVL 23

Expert Comment

by:chensu
ID: 1163963
Yes, the Mouse Hook Procedure and export it.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question