12-02-2024 06:51 PM
I'm trying to write an actor VI that will handle a few keyboard shortcuts for a strong control. For example, Ctrl-A should select all. I was hoping an event structure would allow me to detect that keyboard combination. But Key Down(?) doesn't work: Pressing and holding control fires off the event for Key Down(?), but then pressing any other keyboard character fails to fire the same event.
I can make it work using the Key Up event, but this doesn't select the text until after the keys are up, whereas the normal select-all behavior in most applications will do the text selection while the keys are still pressed.
Turns out that the need to detect control-key on a key down event exists elsewhere. For example, I have string filtering on arrow keys (do something when an arrow key is pressed while in a strong control), but this prevents the default ctrl-arrow key behavior. I need to detect whether the control key is pressed to keep the expected text-selection behaviors.
Any ideas?
Solved! Go to Solution.
12-02-2024 07:15 PM
You can use the customized runtime menu. It works even the menu bar is not visible.
12-02-2024 07:15 PM
I note that the key-down event won't fire if a control-key shortcut in the menus is in use. However, in my running VI, there are no menus shown. If I make a sample VI, ctrl-a is grayed out (it's an edit-only feature of the LV environment). So seems to me it should work.
Also, if this is normal text-input behavior, it should work out of the box!
12-02-2024 07:21 PM
The event data for the key down events has a "PlatMods" section that includes ctrl, so you'd look for 'A' with the ctl mod.
12-02-2024 07:32 PM
> ctrl-a is grayed out
You have to create a customized menu. See attached VI.
12-02-2024 09:03 PM
Thanks @avogadro5 but as I mentioned, this does not work on the Key Down event. Have you tried it?
@zou Thank you for the suggestion, that looks like it will work, though I'll need to look into creating this menu item programatically.