LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Repeatedly trigger an event when a button is held down?

I have an event structure that handles a Mouse Down event for a button.  When the button is pressed it switches to the next menu in my user interface. Is it possible to repeatedly trigger the event code while the button is being held down?  So holding the button would repeatedly scroll through all the various menus in my UI.


0 Kudos
Message 1 of 8
(4,713 Views)

hi there

here's my suggestion:

1. create a event case for "button.value changed". this will handle the event
2. create a while loop that polls the value of button with a rate of lets say 20Hz
3. if the value of button is TRUE (button pressed) then set the val(signl) property of the button object to TRUE in your while loop
4. the val(sgnl) property will fire the event button.value changed even if the value remains TRUE
5. your event case and so your code will then be executed with a rate of 20 Hz
6. maybe you have to handle the button.mouse up event to set the value of button back to FALSE

i don't have LV at hand by now to try this out, but i think this schoukd work

 

 

 

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 2 of 8
(4,693 Views)
I was going to suggest you could use the Timeout in your event structure to check if the mouse button is still down, and if so, go to the next tab.  The downside to this is that you'd wind up checking the status of the mouse button every single timeout period.
0 Kudos
Message 3 of 8
(4,681 Views)
Sounds like you would be better off with a state machine architecture.
0 Kudos
Message 4 of 8
(4,677 Views)
Here is an example that uses a shift register to hold the status of the mouse button being held down and then resets it with a mouse up event. You might be able to use this shift register and the timeout portion of the event structure to know if the mouse button is still pressed.
 
Message 5 of 8
(4,672 Views)
You can do all with one single event case.
  1. Create a shift register to keep the timeout value, initialized to "-1" (=wait forever).
  2. Set the button to "switch until released" and create a "value changed" event for it.
  3. Also assign the timeout to the same event.
  4. In the event case, add a case structure linked to the button.
  5. In the TRUE case, set the timeout to your desired repetition delay and increment your menu (or whatever).
  6. In the FALSE case, set the timeout back to -1.
  7. The event will register a value change (1) when you press OR (2) when you release the button, then (3) repeat via timeout if the button is still pressed.

Attached is a simple demo, modify as needed.

 

Message Edited by altenbach on 07-15-2006 11:31 PM

Message 6 of 8
(4,669 Views)
altenbach:

Your suggestion sounds like it would work, but I can't have the event fire when the button is pressed and when it is released. One button press has to switch the menu to the next item only once.

Is it possible to cause a Mouse Down or Mouse Up event to fire programmatically?  That way I could leave the button set as Switch Until Released so I could check when it is being held down, but I could set the event structure to handle only the Mouse Down event so I wouldn't get two events for when I press and release the button.

Message Edited by DanPHS on 07-16-2006 11:52 AM

Message Edited by DanPHS on 07-16-2006 11:53 AM

0 Kudos
Message 7 of 8
(4,658 Views)


@DanPHS wrote:
Your suggestion sounds like it would work, but I can't have the event fire when the button is pressed and when it is released. One button press has to switch the menu to the next item only once.


Of course I don't know your exact requirements, but maybe you can just place the main event code in the TRUE case of the little case structure. This way it will not execute when the button is released.
0 Kudos
Message 8 of 8
(4,649 Views)