LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Combine "Key Down" and "ValueChange" events?

Solved!
Go to solution

Hello,

 

I have a string control box where a barcode is entered. I want to detect two possible events which should trigger the same action:

 

Event 1: Loss of Focus ( = Value Change)

For example, someone puts the focus on the string control box and changes a digit, then changes focus (without pressing enter). At the time that the focus is lost, this event is triggered.

 

Event 2: Key Down "Enter"

Anytime that the "enter" key is pressed in the string control box. I can filter VKey to check if it is the "enter" key or not. For example, a user might highlight the barcode and press enter to indicate the barcode should remain unchanged.

 

My problem is, I need to trigger on both events, but only once.

 

If I have two separate event cases, Event 2 will also trigger Event 1, so my action will be enqueued twice. Not good.

 

I am not yet sure how to combine both event cases into a single event, which only triggers once on either "keypress enter" or "lost focus, aka Value Change". Any suggestions?

 

See below. Thank you!

 

LabViewCombinedEvent2.PNG

0 Kudos
Message 1 of 10
(5,983 Views)

As far as I know, you can't pull the event data for a specific event if two events in that case don't share that event data.

 

Does the user always press Enter to finish entering data, or click away? If you made the string set to Limit to Single Line, the Enter key will produce a value change event and you could just use that single event.

Cheers


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

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


0 Kudos
Message 2 of 10
(5,963 Views)

Your picture is not suficient to troubleshoot the problem. What are the proerties of the string control, for example?

 

What if you would change the control to "limit to single line" and "update while typing" and only use a "value changed" event?

You get an event for each character, at which point you can look at the value (e.g. the number of characters, etc.) and decide how to further process it (or not).

0 Kudos
Message 3 of 10
(5,955 Views)

There are different approaches for your problem.

 

You can set the option "update value while typing" on your string control so your event "value change" will trigger after each character so you can evaluate the barcode as user types.

 

Second option is to keep that option to false but use the String control property node "Text.Text" on Key down event to evaluate your barcode. That property get refreshed even if the focus is not lost thus value not yet reflecting what's shown on UI.

 

Jimmy

0 Kudos
Message 4 of 10
(5,947 Views)

Thank you for your reply. I am adding a further clarification and an example VI.

 

I think that maybe I have to filter redundant events in the consumer loop, but this seems messy.

 

Is there a neat way to capture every event, but avoid generating redundant events in the first place?

 

See code and attached example VI below.

 

Thanks!

 

Redundant Event Problem

0 Kudos
Message 5 of 10
(5,875 Views)

@James.Morriƽ wrote:

As far as I know, you can't pull the event data for a specific event if two events in that case don't share that event data.

 

Does the user always press Enter to finish entering data, or click away? If you made the string set to Limit to Single Line, the Enter key will produce a value change event and you could just use that single event.


 

 

Thanks for your suggestion. That was the first thing I tried - only use the value change event. 

 

However, a value change event is not triggered when the existing barcode is confirmed as-is with the "Enter" key, without actually retyping any of the barcode digits.

 

To work intuitively in the real system, the code should ideally trigger only once

 

- when "enter" is pressed in the barcode field

or

- when a value change occurred

 

Basically I need a way to OR combine these two events, but I haven't found a good way yet. Putting them into the same event case eliminates the Vkey terminal that I need for filtering out the "Enter" key. Putting them in separate event cases will occasionally generate redundant events, and this in turn results in redundant actions in the consumer loop.

0 Kudos
Message 6 of 10
(5,865 Views)
Solution
Accepted by topic author Gustep

Switch to dynamically registered events:

 

Dynamic events reg.png

Note that you need to switch to the dynamic events in the event sources list:

Dynamic events.png

 

Then, after every event, you un-register then re-register for the events.  If there was a duplicate event in the queue, this will destroy it.

Message 7 of 10
(5,851 Views)

@Gustep wrote:

 

Thanks for your suggestion. That was the first thing I tried - only use the value change event. 

 

However, a value change event is not triggered when the existing barcode is confirmed as-is with the "Enter" key, without actually retyping any of the barcode digits.


Make sure this is in your ini file (both LabVIEW.ini and your application's ini file).  It will cause teh "Enter" key from the barcode scanner to cause the Value Change event.

 

returnKeyAction=True

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 10
(5,838 Views)

It would seem that the available event timestamp of the ENTER KEY event will match the available event timestamp of the VALUECHANGE event when they are for the same event so if you keep track of those times and don't double-report events with identical timestamps then you should be OK.

0 Kudos
Message 9 of 10
(5,793 Views)

@Kyle97330 wrote:

Switch to dynamically registered events:

 

Note that you need to switch to the dynamic events in the event sources list:

 

 Then, after every event, you un-register then re-register for the events.  If there was a duplicate event in the queue, this will destroy it.


 

Thank you! I confirmed that this results in the desired behavior.

 

Fixed code example is attached - a single user dialog now appears in all the correct cases.

 

Note: I had to add a time delay between the "Enter" keypress and reading out the string control, otherwise the string control output would not yet include the changed value. The sequence of things appears to be:

 

Key Down event happens physically

Key Down event case is triggered

(unless delayed, consumer loop now reacts to Key Down event)

String Control value is updated

 

RedundantEventExampleFixed.PNG

0 Kudos
Message 10 of 10
(5,780 Views)