diff options
author | James Ross-Gowan <rossy@jrg.systems> | 2017-07-25 23:51:40 +1000 |
---|---|---|
committer | James Ross-Gowan <rossy@jrg.systems> | 2017-08-05 02:38:44 +1000 |
commit | 037c7a92792837642626a120a90fb4ef74f7547e (patch) | |
tree | eee94b18c9c31ee46431be5d33c2d17d33e2c04e /osdep | |
parent | e406e814775d0c57797915347a7d27c5cad21011 (diff) |
w32_common: handle media keys
This was attempted before in fc9695e63b5b, but it was reverted in
1b7ce759b1f4 because it caused conflicts with other software watching
the same keys (See #2041.) It seems like some PCs ship with OEM software
that watches the volume keys without consuming key events and this
causes them to be handled twice, once by mpv and once by the other
software.
In order to prevent conflicts like this, use the WM_APPCOMMAND message
to handle media keys. Returning TRUE from the WM_APPCOMMAND handler
should indicate to the operating system that we consumed the key event
and it should not be propogated to the shell. Also, we now only listen
for keys that are directly related to multimedia playback (eg. the
APPCOMMAND_MEDIA_* keys.) Keys like APPCOMMAND_VOLUME_* are ignored, so
they can be handled by the shell, or by other mixer software.
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/w32_keyboard.c | 20 | ||||
-rw-r--r-- | osdep/w32_keyboard.h | 3 |
2 files changed, 23 insertions, 0 deletions
diff --git a/osdep/w32_keyboard.c b/osdep/w32_keyboard.c index edb6acf10e..c298f1f6bd 100644 --- a/osdep/w32_keyboard.c +++ b/osdep/w32_keyboard.c @@ -69,6 +69,21 @@ static const struct keymap vk_map[] = { {0, 0} }; +static const struct keymap appcmd_map[] = { + {APPCOMMAND_MEDIA_NEXTTRACK, MP_KEY_NEXT}, + {APPCOMMAND_MEDIA_PREVIOUSTRACK, MP_KEY_PREV}, + {APPCOMMAND_MEDIA_STOP, MP_KEY_STOP}, + {APPCOMMAND_MEDIA_PLAY_PAUSE, MP_KEY_PLAYPAUSE}, + {APPCOMMAND_MEDIA_PLAY, MP_KEY_PLAY}, + {APPCOMMAND_MEDIA_PAUSE, MP_KEY_PAUSE}, + {APPCOMMAND_MEDIA_RECORD, MP_KEY_RECORD}, + {APPCOMMAND_MEDIA_FAST_FORWARD, MP_KEY_FORWARD}, + {APPCOMMAND_MEDIA_REWIND, MP_KEY_REWIND}, + {APPCOMMAND_MEDIA_CHANNEL_UP, MP_KEY_CHANNEL_UP}, + {APPCOMMAND_MEDIA_CHANNEL_DOWN, MP_KEY_CHANNEL_DOWN}, + {0, 0} +}; + static int lookup_keymap(const struct keymap *map, int key) { while (map->from && map->from != key) map++; @@ -89,3 +104,8 @@ int mp_w32_vkey_to_mpkey(UINT vkey, bool extended) return mpkey; } + +int mp_w32_appcmd_to_mpkey(UINT appcmd) +{ + return lookup_keymap(appcmd_map, appcmd); +} diff --git a/osdep/w32_keyboard.h b/osdep/w32_keyboard.h index 218454322d..b06cdee50c 100644 --- a/osdep/w32_keyboard.h +++ b/osdep/w32_keyboard.h @@ -23,4 +23,7 @@ /* Convert a Windows virtual key code to an mpv key */ int mp_w32_vkey_to_mpkey(UINT vkey, bool extended); +/* Convert a WM_APPCOMMAND value to an mpv key */ +int mp_w32_appcmd_to_mpkey(UINT appcmd); + #endif |