Solved

Hooks for Detecting Global Mouse and Keyboard Movement

Posted on 1997-06-17
4
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

696 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