0

Now I'm working on a project which require me to get mouse moving message from all time. My app only have a tiny windows for configuration purpose and it will not even appear on the desktop for most of the time. What I need is I need to be able to record mouse moving on desktop. meaning people moving their mouse on the desktop (which should be explorer.exe ,right?) and I need to know.

How do I do that? Using c# or C++. using inject? Global hook? I heard that only c++ supports global hook, right?

shawhu
  • 1,217
  • 1
  • 12
  • 27

2 Answers2

1

Yes, you need a global hook, and as far as I know you should use C or C++.

See the docs about function SetWindowsHookEx() & co. (WH_MOUSE hook).

But beware! You must write a global hook in a DLL, and it will get injected in every process with a window, so any bad thing you do will likely crash any other program in your session (including explorer.exe, devenv.exe, etc.).

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • Thanks! I got it. And I can get mouse moving message and button click message. But...I need a little more, I need to tell, whether I'm dragging an icon on desktop and move my mouse OR simply dragging nothing(left mouse button down) on the desktop and move. How am I going to do that? – shawhu Aug 05 '11 at 08:00
  • You are talking about major hacking here. You want to know the internal state of another process. If you get the DLL injected in the explorer.exe, you may check if the mouse is captured (GetCapture() function) and guess whether the user is dragging. What is he dragging (an icon or a selection box) will be far more difficult to get. Maybe you can change your approach and use a "Data Handler" Shell Extension: [link](http://msdn.microsoft.com/en-us/library/cc144163(v=vs.85).aspx) – rodrigo Aug 05 '11 at 08:19
0

You can also use SetCapture. Although it's capabilities are limited compared to a hook, check it out.

the_source
  • 648
  • 1
  • 6
  • 12