From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
elset191

Click Event

Status: New
I would like a click event (Mouse down followed by Mouse up) in addition to the separate mouse down and mouse up.  You can fire a mouse up event without having mouse downed inside a control.  Likewise, you can fire a mouse down event by clicking and dragging and releasing outside of the event.  There have been numerous occasions where I want a click event rather than individual down and up events.
--
Tim Elsey
Certified LabVIEW Architect
5 Comments
altenbach
Knight of NI
So, how long should it have to wait after a mouse down to decide if it is a "mouse down" or "mouse click" event? I think you should implement this yourself by e.g. placing a TRUE in a shift register at the "mouse down" event and check it in the mouse "up event" case. Any other event clears the the state boolean.
GregSands
Active Participant

I'm not sure if the shift-register suggestion will always work.  Firstly, it's pretty easy for a Mouse Move event (or even several) to get in between Down and Up (also possibly user-generated events or dynamic events if there's parallel code).  And secondly, if there is a need to distinguish Mouse Down separately from Down-Up, then putting the action into the Mouse Up event won't do anything if it's just Mouse Down.  Nesting event cases to detect a Mouse Up within the Mouse Down event doesn't work.

 

Two other possible ways to detect a Click:

1) Use the Input Device Control under the Connectivity palette to wait in the Mouse Down event and see if the button goes up again.

2) Use a producer-consumer queue-based framework (or similar) to wait after a Mouse Down to see if there's a Mouse Up (event times get passed as data), meanwhile storing other actions to process otherwise.  But I think this checking needs to happen outside the event loop.

 

Both of these do require a click-length - 250ms seems to be reasonable.

JackDunaway
Trusted Enthusiast

altenbach's suggestion was quickly written, but fundamentally correct.

 

You can get clever with shifting event data between events, and I would use the time field of the mouse down event shifted to the mouse up event. Compare the difference to the click time threshold, and you have a mouse click event, unaffected by the number of events fired in between. The two suggestions by GregS are arguably unnecessarily complex, but it depends on your app!

 

I have never missed the full down-up mouse "click" event, and cannot forsee a use in the future for it. (Buttons have this feature already built in based on the button action.)

Message Edited by mechelecengr on 06-19-2009 08:10 AM
elset191
Active Participant

Good Comments guys.  I figured there'd be some issues with it. 

 

Meche,

As for a use case.  I'm writing a small search utility and have controls that are disabled, which are used to filter the results.  If the user wants to filter a result based on a particular parameter I want him to be able to click inside the control to enable it and begin typing.  Right now I use mouse down, and it works okay.  Just, like you stated, doesn't work as a boolean button would.

--
Tim Elsey
Certified LabVIEW Architect
GregSands
Active Participant

My suggestions were for the case where you want to distinguish Down-Up from Mouse Down-and-hold - and therefore want to do something before you receive a Mouse Up event.  One example I can think is to build and display a custom popup menu, which you may not want to display if there is an "immediate" Mouse Up.  Double-click detection (and distinguishing from Single-click) would also be difficult without an external process (e.g. consumer loop) which was checking for a particular sequence of events.