LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Capture Media Keyboard Keys

Solved!
Go to solution

I would like to detect a keydown event on a keyboard key that is one of the media keys.  The normal LabVIEW event Key Down? doesn't capture these, and the Input Device palette where you can poll the keyboard also doesn't capture these.  The only possible solution I've found is to use the Windows Messaging API posted here.  This appears to be targeted to 32 bit API calls, but appears to work in my Windows 7 x64 with LabVIEW 32 bit.

 

Is there any other solution for detecting key downs, such as Pause/Play, Stop, Next Track?  Thanks.

 

EDIT:  Oh that messaging API may not even be a solution.  I'd prefer if I can capture this keyboard event even when the LabVIEW window is not in focus.  Right now that API requires you pass the handle to the window (which is the VI front panel) and only detects keyboard events if that window has focus.

0 Kudos
Message 1 of 6
(5,240 Views)

Seems related to this idea.

Which probably means you're out of luck for now.

0 Kudos
Message 2 of 6
(5,233 Views)

There are 3 other methods, all require Windows API:

1. Poll Virtural Key code, VK_MEDIA_PLAY_PAUSE is 0xB3, equivlent to Input Device in LabVIEW.

2. Set Global Hot Key.  When the specified key pressed, the specified window gets activated.  Use Event structure to catch the activate event.

3. Set Hot Key. Require C/C++ integration, similar to the Windows Message API in your link.  But a more powerful.

 

 

George Zou
Message 3 of 6
(5,191 Views)
Solution
Accepted by topic author Hooovahh

I haven't found any event-based method for this, but pooling is possible using .net Keyboard class from PresentationCore assembly - see the attached VI.

Message 4 of 6
(5,169 Views)

I assume the #1 Win32 API method George is talking about is using the GetKeyboardState or GetKeyState methods - https://msdn.microsoft.com/en-us/library/windows/desktop/ms646299%28v=vs.85%29.aspx


___________________
Try to take over the world!
0 Kudos
Message 5 of 6
(5,116 Views)

Thanks for the suggestions everyone.  I had some strange behavior but got it working.  After I posted this I tried remapping the media keys to function keys, and figured I could have my VI just look for those function key presses.  But none of the key mapping software I found would work with my media keys.

 

I then tried the posted VI and it didn't work.  So I opened VLC to make sure these buttons actually work.  The media keys controlled VLC just fine, so I went back to the VI that was still running and now the media keys were working.

 

So I'm not quite sure why, but it seemed these media keys were registering until I used them once.  I then closed VLC and it is working fine.  Thanks for the help.

0 Kudos
Message 6 of 6
(5,086 Views)