Why is the Key Focus Property Node Not Working Correctly?

Updated May 17, 2019

Reported In

Software

  • LabVIEW

Issue Details

I have a control that I would like to have key focus when my application runs.  However, if I use the Key Focus property node and run my program, the key focus only gets set occasionally.  Why am I experiencing this behaviour?

Solution

The key focus can only be set on a control if the front panel window has focus.  This means that if a window other than the front panel is selected this property cannot be set.   As a result, if the program is run from the block diagram instead of the front panel the Key Focus property node will not work.  

LabVIEW also does not have the ability to maintain persistent key focus.  This means that if you set the key focus on the front panel and then switch from a different window back to the front panel, the front panel will not remember where the key focus has been set.  

One way to ensure that the key focus is always set no matter how you choose to run your program is to use the Is Frontmost property of the front panel.  If you set the Is Frontmost property of the front panel to true before you set the Key Focus property to true, the key focus will always be set correctly because the front panel will always have focus when the key focus is set.  

To access the Is Frontmost property node, first place a VI Server Reference on your block diagram found in the functions palette at Programming » Application Control. Then right-click the output of the VI Server Reference and select Create » Property For VI Class » Front Panel Window » Is Frontmost.