Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting a mouse button is being clicked

Status
Not open for further replies.

anthonyBurgess

Programmer
Jan 25, 2001
1
GB
Hi there,

I want to know if there is a way to detect the state of a mouse button. i.e. Is it possible to detect that a mouse button is being held down?

Thanks
 
What-ho,

yes, it's possible. Most controls have several mouse events such as MouseDown, MouseUp and MouseMove. From these, you can detect which button is being pressed, released and where the mouse is within the object for which these events have been raised. For instance, if the right mouse button is clicked over a ListBox control, you would use the ListBox_MouseDown(Button,Shift,X,Y) event to detect that a mouse button has been clicked. From this event, you can find which button was pressed, whether the shift key was held down and the x and y coordinates of the mouse pointer within the Listbox when the mouse was clicked. Although there's no MouseIsBeingHeldDown event (as this isn't really an event), you can safely assume that the mouse button is being held down until the MouseUp event is fired for that control.

Hope that helps,


Paul
 
You would have thought so wouldn't you. However, on windows 95 and 98 platforms (haven't tested NT) the events do not always fire - we have a PLC communications application where this is definitely the case.

Pushing the button turns on a remote bit, releasing it should turn it off. However, if the button is clicked very fast, then the mouseup event does not fire as the comms dll function has not returned control to the form, leaving the remote bit turned on (not good). I have even tried using the API function SetCapture to try and get round this (i.e. make the form the only recepiant of any mouse actions) but to no avail.

Any other ideas?
 
Does the contorl you're working with have Drag Drop events. If so, try using these
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top