Catching Alt Key Press with the Key Down Filter Event

Catching Alt Key Press with the Key Down Filter Event

Post by Ames » Tue, 15 Nov 2005 14:42:50


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
 
 
 

Catching Alt Key Press with the Key Down Filter Event

Post by tjw » Wed, 16 Nov 2005 06:41:56

I thought I would let you know you're not alone. I tried for the
longest to figure out a way. Only Alt-F10 and some other strange
combination (which I have forgotten) worked. An NI note said that
Windows doesn't generate a signal for the Alt key itself (which is
strange because hitting just the Alt key will activate the FILE menu
item). The note went on to say that you should be able to tell if the
Alt key was held down when another key was hit using the Platform Mods
boolean. That may have been true for 6.1 (for which the tech note was
written) but in 7.1, the Alt key never shows itself except with the
F10. Obviously, Labview is indeed seeing these keystrokes because all
the keyboard shortcuts using Alt combinations work.

Sorry I couldn't give better news.

tjw

 
 
 

Catching Alt Key Press with the Key Down Filter Event

Post by Ames » Wed, 16 Nov 2005 08:13:33

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


Example.vi:
http://www.yqcomputer.com/
 
 
 

Catching Alt Key Press with the Key Down Filter Event

Post by Ankit » Wed, 16 Nov 2005 08:13:33

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
 
 
 

Catching Alt Key Press with the Key Down Filter Event

Post by pauldave » Wed, 16 Nov 2005 13:43:01

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

Catching Alt Key Press with the Key Down Filter Event

Post by Khali » Thu, 17 Nov 2005 09:13:27

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
 


GetAltKey.vi:
http://www.yqcomputer.com/
 
 
 

Catching Alt Key Press with the Key Down Filter Event

Post by Kileen » Thu, 17 Nov 2005 10:44:08

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
 
 
 

Catching Alt Key Press with the Key Down Filter Event

Post by David Craw » Thu, 17 Nov 2005 19:13:59

 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
 


Catching Alt Key Press Poll with Events(151551).vi:
http://www.yqcomputer.com/ (151551).vi
 
 
 

Catching Alt Key Press with the Key Down Filter Event

Post by Ames » Fri, 18 Nov 2005 08:13:49

AWESOME!  That is exactly what I was looking for.
 
Thanks!!!!
Ames
 
 
 

Catching Alt Key Press with the Key Down Filter Event

Post by parthab » Fri, 06 Jun 2008 18:40:07

Can anybody confirm whether this problem is fixed?
Seems not to be so even in LV 8.5.1. :smileysad:
 
 
 

Catching Alt Key Press with the Key Down Filter Event

Post by parthab » Fri, 06 Jun 2008 18:40:07

Can anybody confirm whether this problem is fixed?
Seems not to be so even in LV 8.5.1. :smileysad: