From 0af8811b15f25304ef04013b630ac324011144c0 Mon Sep 17 00:00:00 2001 From: James Ross-Gowan Date: Thu, 13 Oct 2016 22:40:12 +1100 Subject: 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+ and Ctrl+LEFT/RIGHT work, but Ctrl+Alt+ and Ctrl+ 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 --- osdep/terminal-win.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'osdep/terminal-win.c') 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); } } } -- cgit v1.2.3