ni.com is currently experiencing unexpected issues.
Some services may be unavailable at this time.
07-25-2022 11:35 PM
Hi
Attached is a simple vi "Key down Boolean Event.vi" (LV 21) that demo's the problem. I have mapped the F4 key to my boolean control to toggle it.
I would have expected the "Button":Key Down? event to fire when you press the F4 Key, however it never does.
I created a Pane Key Down Event and I can see the F4 key being pressed.
Mouse Down filter events work as expected... so I am surprised key down events don't work.
With Mouse Down filter, the Pane is executed first, and then the control mouse down...
My expectation was that a key is pressed - LabVIEW fires the VI's Pane keydown? Filter, and then if the key is mapped to a control, it should fire the control's Keydown? filter event.
I discovered this as I was wondering why a key down filter event callback wasn't working. Mouse down callback works fine.
Is there a reason why this is not working? Any suggestions as it feels like a bug to me...
Cheers
Solved! Go to Solution.
07-26-2022 12:07 AM
You get a key down event for a control if a key was pressed while that control has focus. Your control presumably doesn't have focus, so you don't get the event. Try tabbing to the control and see if it works then. You might think that you could use the panel's filter event and set the focus there, but that won't work.
The obvious answer is to use the value change event. Setting the key navigation to toggle the control should generate that event.
07-26-2022 12:23 AM
Hi
thanks for prompt response. I saw that somewhere - I tried setting KeyFocus with a property node with no luck for a test.
Its a bit annoying that the Boolean control needs KeyFocus for the KeyDown event to work...
Control Focus makes sense for a string control, but not really for a boolean toggle key.
Cheers
07-26-2022 08:34 AM
I don't see an attachment.
07-26-2022 08:43 AM
@KiwiWires wrote:
Its a bit annoying that the Boolean control needs KeyFocus for the KeyDown event to work...
Control Focus makes sense for a string control, but not really for a boolean toggle key.
I don't see how Key Down makes sense without focus. How else would you know to associate the event with the control? I don't think I ever used the Key Down event for a boolean. Anything wrong with the value change event?
07-26-2022 10:46 AM - edited 07-26-2022 10:49 AM
@KiwiWires wrote:
I created a Pane Key Down Event and I can see the F4 key being pressed.
So why don't you use that instead?
(you already got good answers about the problem, so I won't repeat that)
Key down event should typically be avoided because they are not really safe. For example, they will trigger even if the control is disabled, or even if it is an indicator.
07-26-2022 11:12 AM
An event case can respond to more than one event. Does that help?
07-26-2022 04:24 PM
Thanks for all the replies, sorry didn't realize the attachments didn't attach. Try again.
A new day and I remembered about Tabbing and enter or space on keyfocus which activates the boolean and runs the button's Key down? event. So at least it does fire if activated the right way.
What I was looking for was a filter event for the toggle key.. (I have set to F4).
I added the other filter events for the button, but only the panel gets the F4 key down event. Which seems to be a bit of a hole in the implementation.
Seems what I really need is a "Pre-Value Change Filter" event... that fires after mousedown / keydown / F4 toggle etc as I want to choose if the value change event is run or not.
I am starting to feel that the behavior is "as expected" however its not useful... where I was hung up yesterday was I linked my head F4 key to the button's key down filter event, when its not linked to that specific event.
So now I understand - I can disable the F4 key in code if present - and achieve what I want to achieve.
The other way would be to catch the value change event, decide to discard or not and if not, throw a user event to run the actual on value change code. But ideally wanted code that could be added easily semi-programmatically without rewriting the button value change event cases.
07-26-2022 04:57 PM
So all you really need is a value change event on the button and it will fire if you press F4 or if you click the button. What else do you want?