LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Catching Alt Key Press with the Key Down Filter Event

I am writing an application that requires specific key combinations using ctrl, shift, and alt in addition to a function key (F1, F2, F3, etc).  The application works great except for when I try to catch an alt key press.  The alt key press does not seem to fire an event eventhough it is an option in the PlatMods cluster as well as the VKey enum.  When I press the alt key when my application is running the cursor changes to a normal mouse pointer from the usual finger pointer and prevents any other key presses from going through (in addition to not firing an event itself).
 
I have tried completely removing the run-time menu, which doesn't seem to help.  I currently discard all keys after I handle them in my event structure.
 
I really hope that the only solution isn't using a Windows DLL.  Any suggestions or ideas at all would be greatly appreciated.
 
Thanks,
Ames
0 Kudos
Message 1 of 15
(7,531 Views)

Hi Ames,

There is a problem with Windows and the way it handles the system keys (Alt key). The operating system doesn't send LabVIEW a message so the event structure cannot respond to it. However, you can still see if the Alt key has been pressed in conjunction with another key by reading the PlatMods cluster inside the Key Down event case. One of the elements inside the PlatMods cluster is a Boolean that indicates whether the Alt key was pressed when the event occurred.

Hope this helps,

Ankita

0 Kudos
Message 2 of 15
(7,504 Views)
Thanks for responding Ankita.
 
I am currently monitoring the PlatMods cluster and I can never get that boolean to light up alone or when I press another key.  Do you have an example that does this?
 
I attached a simple example that just displays the VKey and PlatMods cluster when you press a key.  You will notice that shift and ctrl work well, but as soon as you press alt, even with another key, it stops working (until you press alt again).  What is the work around for catching alt key presses?  I have tried using a blank run-time menu.
 
Thanks,
Ames
0 Kudos
Message 3 of 15
(7,498 Views)
I can only get the ALT key light to go on if I also press the Ctrl key (before or after).  It presumably has something to do with the menubar being activated (even when it is hidden).
0 Kudos
Message 4 of 15
(7,492 Views)

Yes, looks like though LabVIEW knows about the ALT key-press, it isn't passing it along.  I am attaching a VI which uses the Windows API function 'GetKeyState' to get this info'.  This works for either ALT key (left/right), but if you're interested in which one, you can replace the virtual-key code accordingly (xA4 and xA5).

-Khalid

 

Message 5 of 15
(7,480 Views)
Hi Ames,

Unfortunately the ALT key is registered as a system key on Windows platforms.  All system keys, regardless of OS, are sent to the OS and LabVIEW does not ever get the message.  This is actually a problem with all system keys regardless of platform. 

You will want to use Khalid's response and make a call to the Windows API to intercept the ALT key press (good job Khalid with your example VI, btw!). 

Best of luck with your application! 

Happy coding,
Kileen
0 Kudos
Message 6 of 15
(7,459 Views)

 Hi Ames

As Kileen has said Khalid has already given you a good solution to detect the ALT key.

I have another approach that might let you stick to your event-driven approach. I suggest that you have another loop in your app that polls the keyboard using the Input Device utility vi's. When this poll loop sees an ALT + KEY combo it raises a dynamic user event and will be processed in your event structure. This means you can keep your key down filter event to process the CTRL + KEY and SHIFT + KEY events.

Example attached in 7.1

cheers

David

 

Message 7 of 15
(7,438 Views)
AWESOME!  That is exactly what I was looking for.
 
Thanks!!!!
Ames
0 Kudos
Message 8 of 15
(7,418 Views)
This was reported to R&D (# 44SCCJBW) for further investigation.  Thanks for the feedback!
0 Kudos
Message 9 of 15
(7,153 Views)

Can anybody confirm whether this problem is fixed?

Seems not to be so even in LV 8.5.1. Smiley Sad

- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 10 of 15
(6,686 Views)