ni.com is currently experiencing unexpected issues.

Some services may be unavailable at this time.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean Toggle Key does not trigger Key Down? Event

Solved!
Go to solution

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

 

0 Kudos
Message 1 of 9
(3,279 Views)

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.


___________________
Try to take over the world!
0 Kudos
Message 2 of 9
(3,262 Views)

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

0 Kudos
Message 3 of 9
(3,256 Views)

I don't see an attachment.  

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 9
(3,216 Views)

@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?


___________________
Try to take over the world!
0 Kudos
Message 5 of 9
(3,212 Views)

@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.

0 Kudos
Message 6 of 9
(3,189 Views)

An event case can respond to more than one event.  Does that help?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 9
(3,174 Views)
Solution
Accepted by topic author KiwiWires

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). 

KiwiWires_0-1658869939276.png

 

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. 

 

Download All
0 Kudos
Message 8 of 9
(3,136 Views)

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?

0 Kudos
Message 9 of 9
(3,128 Views)