diff options
author | James Ross-Gowan <rossymiles@gmail.com> | 2016-10-13 22:40:12 +1100 |
---|---|---|
committer | James Ross-Gowan <rossymiles@gmail.com> | 2016-10-14 08:44:33 +1100 |
commit | 0af8811b15f25304ef04013b630ac324011144c0 (patch) | |
tree | b51ec3f2f2e2ca653c6b546f9f45000238cfc272 | |
parent | 6a8d1cdd49ca6c9d4656b9450253c71438ef5c49 (diff) | |
download | mpv-0af8811b15f25304ef04013b630ac324011144c0.tar.bz2 mpv-0af8811b15f25304ef04013b630ac324011144c0.tar.xz |
terminal-win: support modifier keys in console input
Keyboard input in the console still isn't quite as flexible as it is in
the video window. Ctrl+<letter> and Ctrl+LEFT/RIGHT work, but
Ctrl+Alt+<letter> and Ctrl+<number> do not. Also, in the new Windows 10
console, a bunch of Ctrl keystrokes including Ctrl+UP/DOWN are handled
by the console window and not passed to the application.
Unlike in w32_common.c, we can't really translate keyboaard input
ourselves because the keyboard layout of the console window (in
conhost.exe) doesn't necessarily match the keyboard layout of mpv's
console input thread, however, using ToUnicode as a fallback when the
console doesn't return a unicode value could be a possible future
improvement.
Fixes #3625
-rw-r--r-- | osdep/terminal-win.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c index 0064550b42..c75fe68761 100644 --- a/osdep/terminal-win.c +++ b/osdep/terminal-win.c @@ -92,14 +92,26 @@ static void read_input(HANDLE in) UINT vkey = record->wVirtualKeyCode; bool ext = record->dwControlKeyState & ENHANCED_KEY; + int mods = 0; + if (record->dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) + mods |= MP_KEY_MODIFIER_ALT; + if (record->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) + mods |= MP_KEY_MODIFIER_CTRL; + if (record->dwControlKeyState & SHIFT_PRESSED) + mods |= MP_KEY_MODIFIER_SHIFT; + int mpkey = mp_w32_vkey_to_mpkey(vkey, ext); if (mpkey) { - mp_input_put_key(input_ctx, mpkey); + mp_input_put_key(input_ctx, mpkey | mods); } else { // Only characters should be remaining int c = record->uChar.UnicodeChar; + // The ctrl key always produces control characters in the console. + // Shift them back up to regular characters. + if (c > 0 && c < 0x20 && (mods & MP_KEY_MODIFIER_CTRL)) + c += (mods & MP_KEY_MODIFIER_SHIFT) ? 0x40 : 0x60; if (c >= 0x20) - mp_input_put_key(input_ctx, c); + mp_input_put_key(input_ctx, c | mods); } } } |