LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to press the enter key and the buttons on my VI switch until enter is released.

I have created several VIs for a project at work. One of the requirements we are trying to meet is navigating the user interface with Tab and pressing Enter to activate a button. Tabbing works of course. But when I press the Enter key, the button remains switched down. I have to press it twice to have it come back up. I want to be able to press it once and it comes back up. If I press it with the mouse it switches only as long as I have the mouse clicked.  The mechanical action for all the buttons is Switch Until Released, so that is not the issue.

 

I have seen some similar posts about wanting the Enter key to press a specific button, and that is not what I'm wanting to do. I want to navigate to any button with Tab, press Enter, and have the button go down and back up. Currently I can just press Enter twice to have this happen, but I'd prefer to only have my users have to press it once.

 

This seems to not be how Labview wants it to work but I'm hoping someone knows a way.

0 Kudos
Message 1 of 11
(756 Views)

A mechanical action of "switch until released" is probably not the right mechanical action. Why do you think it is?

 

Try latch action and make sure the terminal is in the location where it is read by the code to properly reset.

 

We can give more specific advice once you attach a simplified version of your VI (Make sure to "save for previous, 2020 or below). What do the buttons actually do?

0 Kudos
Message 2 of 11
(752 Views)

Are you using an event structure, or could you add one?

 

If so, you can use the Key Down and Key Up events to both capture which control has focus (i.e. it was tabbed to) and if the key pressed was the Enter key or not:

Kyle97330_0-1711494771040.png

You can then use that to do... whatever it is needs to be done when someone presses Enter.

0 Kudos
Message 3 of 11
(729 Views)

I have tried every other mechanical action and they all work the same way with enter as a key activation.

 

I can't share the whole program but will take out a slice when I'm able and share here. Thanks for the instruction.

0 Kudos
Message 4 of 11
(663 Views)

@JWH2 wrote:

I have tried every other mechanical action and they all work the same way with enter as a key activation.


Latch action booleans reset back to the default state when the terminal is read by the code, so if the terminal is e.g. on the toplevel diagram outside the toplevel loop or hidden inside a case that does not execute, it will never get read during run. If they are linked to an event, it is best to place the terminal inside that event. (We also need to assume that your architecture is sane and the event is always ready to execute and not hidden in structures or other parts of the diagram that are blocked by dataflow.)

 

"XXX until released" acts like a car horn such that the value is TRUE as long as you hold the button down with the mouse (and if you use an event structure, you'll get two events, one on press and one on release). But if you poll it, you might get multiple TRUEs or miss it completely, depending on the loop rate and other factors. If you really (really!!!!???) want to duplicate that with keys (i.e. do "something different" as long as the key is held down), you can implement anything you want with some code, of course.

 

With questions like that, it helps to give some context on what these buttons actually do.

 

0 Kudos
Message 5 of 11
(652 Views)

Do you want to toggle the state of the button from "unpressed" to "pressed" one single time when you press Enter, or do you want the button held down the entire time you're pressing and holding Enter?

0 Kudos
Message 6 of 11
(631 Views)

I don't need to be able to hold it down. I want to hit enter and it press and unpress. If it stays down while I'm holding it that's fine, but it's not necessary.

 

When I just click and release with the mouse, the button presses then depresses on it's own. When I press enter and release, the button stays down instead of coming back up. I want it to have the same actions as with the mouse.

0 Kudos
Message 7 of 11
(616 Views)

@JWH2 wrote:

When I just click and release with the mouse, the button presses then depresses on it's own. When I press enter and release, the button stays down instead of coming back up. I want it to have the same actions as with the mouse.


We seem to be going in circles. Why don't you attach a simplified VI to show us what you are doing. My guess is still that you are not using the correct mechanical action and have poor code architecture.

0 Kudos
Message 8 of 11
(605 Views)

I think that the requirement to use the Enter key as well is going to make it tricky because you will have to guard against someone leaning on the Enter key and causing multiple Enter key events.  This doesn't happen with button presses because the event doesn't fire until the button is released.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 11
(601 Views)

Oh I will be, I am just not able to at the moment. Making something I can post here will require me to strip out several connections to subVIs and some data handling. Which is doable, I just have not had time yet. I'm not meaning to go in circles, I will hopefully have time tomorrow.

0 Kudos
Message 10 of 11
(592 Views)