01-05-2016 06:08 PM - edited 01-05-2016 06:19 PM
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!
Solved! Go to Solution.
01-05-2016 06:23 PM
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> ---'
01-05-2016 06:34 PM
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).
01-05-2016 06:40 PM
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
01-06-2016 10:12 AM
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!
01-06-2016 10:25 AM
@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.
01-06-2016 10:53 AM - edited 01-06-2016 10:54 AM
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.
01-06-2016 11:10 AM
@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
01-06-2016 04:24 PM - edited 01-06-2016 04:25 PM
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.
01-06-2016 04:51 PM - edited 01-06-2016 04:54 PM
@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