07-02-2026 04:02 AM - edited 07-02-2026 04:03 AM
This is a simple VI. If the UP or Down key is clicked the value counter is increased/decreased.
There is control Numeric. The operator can place cursor in this control and increase/decrease its value with the same two keys. There is a side effect. The value of counter is also changed.
Is there any way to prevent counter from changing its value when operator uses keys to set value of another numeric control?
Note: This VI only illustrates my question. The real GUI has many numeric controls. Thus monitoring of each numeric control is out of question.
Solved! Go to Solution.
07-02-2026 04:08 AM - edited 07-02-2026 04:10 AM
Hi Y,
@_Y_ wrote:
Is there any way to prevent counter from changing its value when operator uses keys to set value of another numeric control?
So you create an event case where you wait for ANY "key up" event and when it is the UP key you increase that "counter".
I don't see any "side effect": the event case does exactly what you have programmed to do!
@_Y_ wrote:
There is a side effect. The value of counter is also changed.
Remove the code that increments the "counter"…
Different question: when do you REALLY want to increment this "counter"?
07-02-2026 04:17 AM
I'm not sure what is your goal you're trying to achieve, but it sounds like you need to discard the key event. Maybe this approach would work, at least as an idea:
07-02-2026 04:34 AM
@_Y_ wrote:
The operator can place cursor in this control and increase/decrease its value with the same two keys.
You don't need code for that. The control already supports this behavior. If the control has focus, depending on where the cursor is (which you can control with the left/right keys or the mouse), different digits will be incremented or decremented when you press the up/down keys.
07-02-2026 04:34 AM
wrote:
Hi Y,
Different question: when do you REALLY want to increment this "counter"?
Probably I shall reformulate the question.
I need to monitor use of UP and DOWN keys if they are not used for direct control of numeric values.
or
I need to monitor use of UP and DOWN keys if no numeric control has forcus.
@Andrey_Dmitriev wrote:
it sounds like you need to discard the key event.
If I discard the event, the operator cannot use the same key for setting values in Numeric.
07-02-2026 04:44 AM
@_Y_ wrote:
If I discard the event, the operator cannot use the same key for setting values in Numeric. Is there any way to prevent counter from changing its value when operator uses keys to set value of another numeric control?
Well, if the "another" is key word in this task, then may be switch to Key Up from control and check reference, from which is it triggered?:
07-02-2026 04:58 AM
@Andrey_Dmitriev wrote:
switch to Key Up from control and check reference, from which is it triggered?
If I understand it correctly, this will require setting focus to certain control. But I want to avoid it.
07-02-2026 05:19 AM
@_Y_ wrote:
wrote:
Hi Y,
Different question: when do you REALLY want to increment this "counter"?
Probably I shall reformulate the question.
I need to monitor use of UP and DOWN keys if they are not used for direct control of numeric values.
or
I need to monitor use of UP and DOWN keys if no numeric control has forcus.
@Andrey_Dmitriev wrote:
it sounds like you need to discard the key event.
If I discard the event, the operator cannot use the same key for setting values in Numeric.
Does this cover all cases? I forgot to remove the strict qualifier, but otherwise may cut it.
07-02-2026 05:42 AM
Hi Y,
@_Y_ wrote:
wrote:
Hi Y,
Different question: when do you REALLY want to increment this "counter"?
Probably I shall reformulate the question.
I need to monitor use of UP and DOWN keys if they are not used for direct control of numeric values.
or
I need to monitor use of UP and DOWN keys if no numeric control has forcus.
Part of being a good/better programmer is the ability to describe code requirements with all needed details.
You forgot that "if" in your initial message…
All you need to do is to implement the "if" in your code!
On the "key focus" property: you could create an user event that handles all your numeric controls. Whenever any of the controls get focus you could set a flag and when the controls lose focus you clear the flag. Use that flag for your "if" condition…
07-02-2026 07:05 AM
@cordm wrote:
Does this cover all cases?
Thank you, it does the work.
Shame on me. I don't like error-driven logic and always forget to think in its way.