开发者

Windows API for common media player functions?

Lots of keyboards have common media functions like next/previous, play/pause and stop. Do they use some existing API in Windows, or do they implement functions specific to the most popular media players (WMP, WinAmp, Spotify...)? All keyboards I've owned which have开发者_如何学Go this functionality have just seemed to work with everything, regardless of age of the keyboard vs the software, so I thought there might be an already built API for this.

If they use an already existing API in Windows, where can I find info about it?

Just to clarify: I'm not looking for a way to interact with Windows Media player specifically. I want to find that one magic button to hit to reach all (supported) media players - if one such exists.


They simply generate a virtual key code that DefWindowProc() recognizes. Copied straight from the WinUser.h header file:

#if(_WIN32_WINNT >= 0x0500)
#define VK_BROWSER_BACK        0xA6
#define VK_BROWSER_FORWARD     0xA7
#define VK_BROWSER_REFRESH     0xA8
#define VK_BROWSER_STOP        0xA9
#define VK_BROWSER_SEARCH      0xAA
#define VK_BROWSER_FAVORITES   0xAB
#define VK_BROWSER_HOME        0xAC

#define VK_VOLUME_MUTE         0xAD
#define VK_VOLUME_DOWN         0xAE
#define VK_VOLUME_UP           0xAF
#define VK_MEDIA_NEXT_TRACK    0xB0
#define VK_MEDIA_PREV_TRACK    0xB1
#define VK_MEDIA_STOP          0xB2
#define VK_MEDIA_PLAY_PAUSE    0xB3
#define VK_LAUNCH_MAIL         0xB4
#define VK_LAUNCH_MEDIA_SELECT 0xB5
#define VK_LAUNCH_APP1         0xB6
#define VK_LAUNCH_APP2         0xB7

#endif /* _WIN32_WINNT >= 0x0500 */

Since all windows call DefWindowProc(), you can simply use SendInput or keybd_event to send the keystroke.


this is just a virtual key code - for an official list see MSDN.

There you find for example VK_VOLUME_UP VK_MEDIA_PLAY_PAUSE VK_ZOOM

Even some Remotes translate to these codes to be as compatible as possible with existing software..

EDIT - as per comment:

These were introduced back in the day when Windows ME (!) came out and are still in use - at least when I checked the registry of my Windows 2008 R2 !

Basically Windows translates certain VK* into WM_APPCOMMAND messages with certain codes which the applications listen to...
If the key has something to do with launching an app to do (i.e. Mail, Browser etc.) then the magic happens via Windows Explorer which reads the mapping (either by association or direct exec) from the registry at Software\ Microsoft\ Windows\ CurrentVersion\ Explorer\ AppKey - either HKLM or HKCU.

Some links with old but as it seems still valid information:

  • Enhanced Keyboards and Windows
  • Archive: HID Audio Controls and Windows
  • Archive: Key Support, Keyboard Scan Codes, and Windows
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜