Hooks for Detecting Global Mouse and Keyboard Movement

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.
   
vjeanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vjeanAuthor Commented:
Edited text of question
0
chensuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vjeanAuthor Commented:
What exactly do I put into "my.dll"?
The Mouse Procedure or something?

0
chensuCommented:
Yes, the Mouse Hook Procedure and export it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.