Hooking the Mouse
-
I am trying to write a piece of code that spawns a window when the user presses both mouse buttons simultaneously. I have been thinking the only way to do this would be to have two mouse hooks, watching for left and right clicks respectively, and checking the time difference between clicks. It would then cancel the message if the time is within a certain interval, and show the window. Any better ideas? Please?
All your source are belong to us!
-
I am trying to write a piece of code that spawns a window when the user presses both mouse buttons simultaneously. I have been thinking the only way to do this would be to have two mouse hooks, watching for left and right clicks respectively, and checking the time difference between clicks. It would then cancel the message if the time is within a certain interval, and show the window. Any better ideas? Please?
All your source are belong to us!
The easiest way would be to handle the click event and check the state of the buttons inside the event. The following will close the form if both buttons are depressed:
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e _ As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick If e.Button = Windows.Forms.MouseButtons.Left Then If MouseButtons = Windows.Forms.MouseButtons.Right Then Me.Close() End If End If If e.Button = Windows.Forms.MouseButtons.Right Then If MouseButtons = Windows.Forms.MouseButtons.Left Then Me.Close() End If End If End Sub
Hope this helps. Keith -
The easiest way would be to handle the click event and check the state of the buttons inside the event. The following will close the form if both buttons are depressed:
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e _ As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick If e.Button = Windows.Forms.MouseButtons.Left Then If MouseButtons = Windows.Forms.MouseButtons.Right Then Me.Close() End If End If If e.Button = Windows.Forms.MouseButtons.Right Then If MouseButtons = Windows.Forms.MouseButtons.Left Then Me.Close() End If End If End Sub
Hope this helps. Keith