mirror of
https://github.com/mpv-player/mpv
synced 2024-11-03 03:19:24 +01:00
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
This commit is contained in:
parent
6a8d1cdd49
commit
0af8811b15
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user