04-20-2016 09:46 AM - edited 04-20-2016 09:48 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
Solved! Go to Solution.
04-20-2016 09:53 AM
Seems related to this idea.
Which probably means you're out of luck for now.
04-20-2016 02:25 PM - edited 04-20-2016 02:29 PM
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.
04-20-2016 03:43 PM
04-21-2016 12:42 AM
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
04-21-2016 08:10 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord