LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

using key to toggle button and retain Mechanical Action

Solved!
Go to solution

I am setting up to control the jogging of a stepper motor and I have 2 buttons for foward jog and reverse jog. These button have mouse down and mouse up events to send the appropriate commands to the motor controller. The mechanical action of the buttons are set to Latch until released.

 

I would also like to use the Page Up and Page Down keys on the keyboard to toggle these buttons. However I would like the button to act in the same manner as with the mouse, when the key is pressed and held the button stays pressed and releases with the release of the key.

However when I press and hold the key the button continues to toggle on and off. Is has something to do with the key repeat but I am not sure how to make it work. Any advice would be appreciated.

 

I have attached an example of how I have started. The mouse down press on the reverse button opens a dialog, but the key down does not and when the key is held down the button flickers. Page Up is for forward and Page Down is for reverse.

 

Regards

Terry

 

0 Kudos
Message 1 of 7
(3,916 Views)
Solution
Accepted by topic author Terry_S

Just use another event and handle key down/key up similarly. You can event switch the button using local variables while active.

 

I am not sure why you use latch action. Why not use switch until released and value change events?

Message 2 of 7
(3,909 Views)

I was busy making an example and Altenbach beat me to the post once again.

 

Here's what your key down event could look like with a simple status string that I put in there to show the functionality. The event only gets triggered once when the user presses the button down. Unfortunately the Key Up event doesn't give you a value for the key, so you have to do some logic with shift registers to figure out which key was released, or just set all booleans to False when Key Up occurs.

Motor Control Example.png

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 3 of 7
(3,895 Views)

I think you need to move your Key Up and Key Down events into separate cases so that you can read which key was pressed.

 

Check out the attached VI in LV2013 - notice that it doesn't keep firing the event while the button is held down.

 

Edit: Damn, looks like we've all jumped in with pretty much the same response! Smiley Very Happy


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 4 of 7
(3,890 Views)

In fact I would even make the two buttons indicators and write the current state to them, depending on mouse down/key down events.

 

Also don't forget the "mouse leave" event to turn the button off when the mouse slips off. In that case, a mouse up would never happen.

 

You also need to decide what should happen if the user presses both buttons.

0 Kudos
Message 5 of 7
(3,879 Views)

Thanks for all the help.  Attached is what was done with your assistance

0 Kudos
Message 6 of 7
(3,847 Views)

I would probably simplify it to three event cases and do the motor control commands after the event structure using a common structure. Simply generate the relevant command strings inside the releveant cases and output an empty string if nothing needs to be done. Place the motor control in a case structure that does nothing if an empty string comes in.

 

Here's a skeleton for the UI. Modify as suggested.

0 Kudos
Message 7 of 7
(3,826 Views)