From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Keyboard triggered counting event

Dear all,

 

I'm trying to use keyboard to trigger the counting action, my Labview program is attached to this post.

 

In the attached IV example, when I assigned 'A' key to trigger 'Test' event, counting how many times 'Test' buttons are pressed (Block diagram in Fig1). 

When I use mouse to click 'Test', the counter increments (Fig2).

However, press 'A', the 'Test' button lights on, but its output is 'not executed', therefore, the counting action is not triggered (Fig3).

 

Similar structure works fine without 'Event Structure' that pressing 'A' key can trigger both 'Test' button and counter. But I will need quite number of buttons, so using 'Event Structure' is preferred. I've tried many ways to wire the 'Test' button to trigger the counter in an event structure, but it did not work when I use keyboard instead of clicking mouse.

Fig1Fig1Fig2Fig2Fig3Fig3

Thank you so much for your help and efforts~~

 

Best regards,

Peter Wang

 

 

 

 

 

0 Kudos
Message 1 of 7
(3,210 Views)

Hi,

 The problem in your code is you have to use Value(Signaling) property to capture the events. I have implemented it successfully. Please find the code.

Give Kudos........
Mark as Solution........ 🙂

 

1.jpg2.jpg3.jpg

Message 2 of 7
(3,179 Views)

Hi to both of you,

 

are there reasons tho handle key press event NOT with an event structure?

(What's the point of a "key press"-event when you still handle the keypress by those Keyboard functions? Why do you need to convert an array to a cluster just to get the first element?)

Are there reasons to use a lot of local variables instead of a shift register?

 

Inspiration:

check.png

(German LabVIEW: "Taste gedrückt" = "key down", "Zeichen" = "char")

Create a second event to handle the test button (and a 3rd one for the stop button)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 7
(3,167 Views)

Hi, 

 

Thank you so much for your help. I did some test on your program, and when I tried to add more buttons (Fig1), all the events are triggered and events are competing (say if I press 'D' for 3 times, count is 0, count#2 is 2, count#3 is 3 (Fig2). Not sure if this instability is caused by using value (signal). Thank you~~.

 

key press fig1.PNGkey press fig2.PNG 

 

 

Best regards,

Peter

 

 

0 Kudos
Message 4 of 7
(3,149 Views)

Hi cwangeee,

 

two points:

- you create an event for each Test button with each key down event

- in your test button events all use the very same shift register. When you want to use different counters each one has to use its own data storage (simplest case: own shift register)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(3,145 Views)

Hi GerdW,

 

Thank you for your reply. I may not understand your suggestions very clearly. Adding shift registers for each button sounds like quite some work to do, say that I have 20 test buttons, and this counting function is one part of the design.

 

You mentioned a good point that it does not need buttons to trigger the counters by pressing keys, but I would like to keep these buttons as indicators showing that the buttons are pressed during the counting. Thanks.

 

Best regards,

Peter 

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

Hi cwangeee,

 

Adding shift registers for each button sounds like quite some work to do, say that I have 20 test buttons, and this counting function is one part of the design.

Then you should keep all "variables" in a cluster: only one shift register to hold the cluster!

(That's what I meant with "each one has to use its own data storage (simplest case: own shift register)": the simplest case would be to use a shift register per counter. The more advanced is to use a cluster for all values…)

 

but I would like to keep these buttons as indicators showing that the buttons are pressed during the counting.

Under "normal" conditions the user will not even notice the blinking of those buttons as the events will be handled very quickly! But that's your design decision…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 7
(3,123 Views)