Monitor mouse events in application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to monitor the status of the mouse on an application-wide basis (i.e., not just for the control that owns the mouse). One I idea I had was to create a shared class that inherits from timer and tests Windows.Forms.Control.MouseButtons and Windows.Forms.Cursor.Current.Position in the tick event. Obviously this technique is not perfect because I am relying on the tick event. Also, I've discovered that Windows.Forms.Control.MouseButtons does not update immediately when the user clicks the title area of a form (i.e., when the form's Text, Icon, and ControlBox are displayed). Is there a better technique

Thank you
Lance
 
* "=?Utf-8?B?TGFuY2U=?= said:
I need to monitor the status of the mouse on an application-wide basis
(i.e., not just for the control that owns the mouse). One I idea I had
was to create a shared class that inherits from timer and tests
Windows.Forms.Control.MouseButtons and
Windows.Forms.Cursor.Current.Position in the tick event. Obviously this
technique is not perfect because I am relying on the tick event. Also,
I've discovered that Windows.Forms.Control.MouseButtons does not update
immediately when the user clicks the title area of a form (i.e., when
the form's Text, Icon, and ControlBox are displayed). Is there a better
technique?

A mouse hook ('WM_MOUSE' or similar) would be a more reliable way:

Article on keyboard hooks (can be adapted for mouse hooks):

<URL:http://www.developer.com/net/net/article.php/11087_2193301_1/>

Documentation on hooks:

<URL:http://msdn.microsoft.com/library/en-us/dnwui/html/msdn_hooks32.asp>
<URL:http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/hooks.asp>
 
Back
Top