LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event control of button press and hold

As part of a more complex application, I need to build an event driven user interface that increments (or decrements) a number.  This was easy enough to accomplish (see attached vi).  Unfortunately, I need the user to be able to press and hold the "UP" button to quickly increase the value.  I using the "Key Repeat" event, but couldn't get it to work.  I'm sure someone has built something like this before - any ideas?  Thanks in advance for your help.
0 Kudos
Message 1 of 14
(8,885 Views)
It sounded familiarSmiley Very Happy
And I thought about an XControl, a quick search on the forums showed this code of mine, which is done best as an XControl but hey you can't have everything


Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 14
(8,877 Views)
Thank you for the reference and code - this looks like it could be a solution.  I was really hoping to avoid extra sub-VIs, background loops, etc.  I will be deploying the final aplication on a thin client with extremely limited resources and was hoping to do everything on an event triggered basis to keep the CPU free.  Has anyone had any success using the "Key Repeat" event with a button?  This seems like it would be the ideal solution, but I have been unable to get it to work.

IDEAL: "Mouse Down" event increments counter once, if button is held, "Key Repeat" event continues to add to the counter over time.

Any ideas? 
Again, thanks Ton for the quick and useful info.
0 Kudos
Message 3 of 14
(8,859 Views)
I adjusted the original code, it shows a counter how many times the 'key repeat' event is triggered, and resets if a different key is used (ascii only)
The rest is up to you (please post)
Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 4 of 14
(8,852 Views)
Ton,
This approach utilizes the VI event "key repeat" - why can't I use the "key repeat" event of the button itself?  This event should intermittently fire as the up button is held down - Am I misunderstanding what this event looks for?
0 Kudos
Message 5 of 14
(8,845 Views)
The key repat event, is a VI event, so it'll only be triggered for VIs.

With < tab> you can select one control (it's quite hard to get inside a cluster) and then a key will be issued to that one control.

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 6 of 14
(8,839 Views)
This is one of those cases where is might be simpler to not use the event structure at all.
Message 7 of 14
(8,831 Views)
After searching on the forums a little more, I decided to try a nested event structure.  It works (see attached) and has the following advantages:

1) simple coding
2) no backround loops to occupy the CPU (surprisingly critical in my final app)
3) buttons are more responsive when driven by events rather than timed checking of their status

From what I understand, nesting event structures is usually discouraged because it can lead to front panel "locking".  I think in this case, it is a reasonable approach because the two nested events are "mouse down" and "mouse up" over a single control.  These two events must follow each other with no other event possible in between (I don't have a keyboard - only a touch screen, so no other user input).

I would be interested to hear some expert takes on this approach.  Thanks to Dennis and Ton for their help.

-Marc
0 Kudos
Message 8 of 14
(8,819 Views)


@petrem wrote:
I think in this case, it is a reasonable approach because the two nested events are "mouse down" and "mouse up" over a single control.  These two events must follow each other with no other event possible in between (I don't have a keyboard - only a touch screen, so no other user input).



Marc,

add 'Mouse Leave' to your list

Uhm why did you need 'key repeat' without a keyboard?

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 9 of 14
(8,800 Views)


@petrem wrote:
After searching on the forums a little more, I decided to try a nested event structure. 


Noooo!!!! Never nest event structures! Your code is overly complicated. It is NOT "simple coding" (your words)! 😄

All you need is three very simple event cases, each containing nearly no code:

  1. UP, DOWN: value change (to enable/disable the timeout)
  2. timeout (to do the timed increment/decrement)
  3. Stop: value change
  • No extra loops!
  • No stacked event structures!
  • No local variables!
  • No sequence structures!
  • No mouse events!

See for yourself in the attached draft (LabVIEW 8.2) ! 🙂

Let me know if anything is not clear.

Message 10 of 14
(8,794 Views)