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.
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.
08-10-2017 09:28 PM
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.
Thank you so much for your help and efforts~~
Best regards,
Peter Wang
08-11-2017 12:45 AM
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........ 🙂
08-11-2017 02:11 AM - edited 08-11-2017 02:19 AM
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:
(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)…
08-11-2017 04:20 AM
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~~.
Best regards,
Peter
08-11-2017 04:45 AM
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)…
08-11-2017 11:14 AM
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
08-11-2017 01:45 PM - edited 08-11-2017 01:47 PM
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…