Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows API for common media player functions?

Tags:

c#

windows

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

like image 290
Arve Systad Avatar asked Feb 02 '23 14:02

Arve Systad


1 Answers

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.

like image 154
Hans Passant Avatar answered Feb 05 '23 17:02

Hans Passant