LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Keyboard input doesn't change page of Tab Control

Solved!
Go to solution

The VI attached is a smaller version of a much larger VI that I simplified to solve this one problem. The gist of it is that I have a tab control, on this VI of only two pages. I would like it that when I hit the button 2 on the keyboard, the Tab Control will go to page 2, and the same for if I hit button 1 on the keyboard it should go to Page 1. But it doesn't. There is no response. I feel like the answer to this is something simple, but I have been able to nail it yet. Suggestions?

0 Kudos
Message 1 of 7
(2,756 Views)

Learn LabVIEW.  Your code uses ideas that come from "traditional" languages, such as Basic, C/C++, Matlab, etc.  LabVIEW uses a Data Flow model, with the concept of Controls (such as Strings that accept typed characters) and Indicators.  It has a type of "User Interrupt" (called an Event Structure) that can detect when a String has been entered, and can interpret what was typed (like a "1", a "2", or "None of the above") and do something about it.

 

Data are not conventionally handled by "variables" -- data live in, and are passed by, "wires".  A beginner with LabVIEW should never use a Local Variable -- it is a mark of a "beginner" or else a very experienced LabVIEW developer who understands the dangers and restrictions on (rarely) using this construct.

 

There are a series of "Learn LabVIEW" links at the beginning of this Forum.

 

Bob Schor

0 Kudos
Message 2 of 7
(2,719 Views)

I agree with @Bob_Schor. You have a classic race condition. You also have your loops sitting there running as fast as they can. Why not add a small wait in your loops, and is there a reason to not process the key press in the same loop in which you're reading it? Finally, yes, the Event structure is your friend.

0 Kudos
Message 3 of 7
(2,708 Views)
Solution
Accepted by topic author ShogunOrta

Here is a simple example using an Event Structure.

0 Kudos
Message 4 of 7
(2,687 Views)

You got a pretty good solution above.

 

Still, some more comments about your code:

An enum is not a tab control, no matter how you label, resize, or call it. (yes, the tab "value" is an enum, but that's a different story).

Learn about dataflow, datatypes, and greedy loops. treating an array of enums as U8 (hint, the type is actually U16) and convert to a string is just plain silly. A red coercion dot is an invitation to take a closer look. Did you? If you know only a single key is pressed, just index out the first element and wire it directly to the case selector.

 

I strongly recommend to start with the basic tutorials. 

0 Kudos
Message 5 of 7
(2,668 Views)

Thanks! This worked very well, and it showed me the proper way to go about this, as others have pointed out. One question though, I see that Labview sees the Button 1 as 49 and Button 2 as 50 and so on. But when I press F1 on my machine, that doesn't seem to register at all. It just shows a 0 for all the F Buttons. Is there a way to use the F keys in the same way I am now using the 1-3 keys?

0 Kudos
Message 6 of 7
(2,664 Views)
Solution
Accepted by topic author ShogunOrta

F1 brings up the LabVIEW help in my case. It also is not a "char". You are already using a filtering event ("key down?" instead of "key down"), so you get the "discard?" terminal. If you discard the F1, it will not be relayed to lthe OS, and the help is not launched.

 

You can play with the "ScanCode" or "VKey" event data nodes to get the information you want.

 

altenbach_0-1583875740686.png

 

0 Kudos
Message 7 of 7
(2,656 Views)