diff --git a/src/qt/qt_winrawinputfilter.cpp b/src/qt/qt_winrawinputfilter.cpp index ccaea1f56..66d7ba3c3 100644 --- a/src/qt/qt_winrawinputfilter.cpp +++ b/src/qt/qt_winrawinputfilter.cpp @@ -172,7 +172,8 @@ void WindowsRawInputFilter::keyboard_handle(PRAWINPUT raw) { USHORT scancode; - static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0; + static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0, recv_lctrl = 0, recv_rctrl = 0; + static int recv_npgup = 0, recv_pgup = 0; RAWKEYBOARD rawKB = raw->data.keyboard; scancode = rawKB.MakeCode; @@ -198,13 +199,13 @@ WindowsRawInputFilter::keyboard_handle(PRAWINPUT raw) We use scan code 0xFFFF to mean a mapping that has a prefix other than E0 and that is not E1 1D, which is, for our purposes, invalid. */ - if ((scancode == 0x00F) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && !mouse_capture) { + if ((scancode == 0x00f) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && (!kbd_req_capture || mouse_capture)) { /* We received a TAB while ALT was pressed, while the mouse - is not captured, suppress the TAB and send an ALT key up. */ + is not captured, suppress the TAB and send an ALT key up. */ if (recv_lalt) { keyboard_input(0, 0x038); /* Extra key press and release so the guest is not stuck in the - menu bar. */ + menu bar. */ keyboard_input(1, 0x038); keyboard_input(0, 0x038); recv_lalt = 0; @@ -212,32 +213,163 @@ WindowsRawInputFilter::keyboard_handle(PRAWINPUT raw) if (recv_ralt) { keyboard_input(0, 0x138); /* Extra key press and release so the guest is not stuck in the - menu bar. */ + menu bar. */ keyboard_input(1, 0x138); keyboard_input(0, 0x138); recv_ralt = 0; } - } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_tab && !mouse_capture) { + } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_tab && (!kbd_req_capture || mouse_capture)) { /* We received an ALT while TAB was pressed, while the mouse - is not captured, suppress the ALT and send a TAB key up. */ - keyboard_input(0, 0x00F); + is not captured, suppress the ALT and send a TAB key up. */ + keyboard_input(0, 0x00f); recv_tab = 0; + } else if (((scancode == 0x049) || (scancode == 0x149)) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && (recv_lctrl || recv_rctrl) && (!kbd_req_capture || mouse_capture)) { + /* We received a NumPad Page Up or Page Up while CTRL+ALT was pressed, while the keyboard + is captured, suppress the Page Up and send an CTRL+ALT key up. */ + if (recv_lctrl) { + keyboard_input(0, 0x01d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x01d); + keyboard_input(0, 0x01d); + recv_lctrl = 0; + } + if (recv_rctrl) { + keyboard_input(0, 0x11d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x11d); + keyboard_input(0, 0x11d); + recv_rctrl = 0; + } + if (recv_lalt) { + keyboard_input(0, 0x038); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x038); + keyboard_input(0, 0x038); + recv_lalt = 0; + } + if (recv_ralt) { + keyboard_input(0, 0x138); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x138); + keyboard_input(0, 0x138); + recv_ralt = 0; + } + } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_npgup && (recv_lctrl || recv_rctrl) && (!kbd_req_capture || mouse_capture)) { + /* We received an ALT while CTRL+NumPad Page Up was pressed, while the mouse + is not captured, suppress the ALT and send a TAB key up. */ + if (recv_lctrl) { + keyboard_input(0, 0x01d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x01d); + keyboard_input(0, 0x01d); + recv_lctrl = 0; + } + if (recv_rctrl) { + keyboard_input(0, 0x11d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x11d); + keyboard_input(0, 0x11d); + recv_rctrl = 0; + } + keyboard_input(0, 0x049); + recv_npgup = 0; + } else if (((scancode == 0x01d) || (scancode == 0x11d)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_npgup && (recv_lalt || recv_ralt) && (!kbd_req_capture || mouse_capture)) { + /* We received an CTRL while ALT+NumPad Page Up was pressed, while the mouse + is not captured, suppress the ALT and send a TAB key up. */ + if (recv_lalt) { + keyboard_input(0, 0x038); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x038); + keyboard_input(0, 0x038); + recv_lalt = 0; + } + if (recv_ralt) { + keyboard_input(0, 0x138); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x138); + keyboard_input(0, 0x138); + recv_ralt = 0; + } + keyboard_input(0, 0x049); + recv_npgup = 0; + } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_pgup && (recv_lctrl || recv_rctrl) && (!kbd_req_capture || mouse_capture)) { + /* We received an ALT while CTRL+Page Up was pressed, while the mouse + is not captured, suppress the ALT and send a TAB key up. */ + if (recv_lalt) { + keyboard_input(0, 0x038); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x038); + keyboard_input(0, 0x038); + recv_lalt = 0; + } + if (recv_ralt) { + keyboard_input(0, 0x138); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x138); + keyboard_input(0, 0x138); + recv_ralt = 0; + } + keyboard_input(0, 0x149); + recv_pgup = 0; + } else if (((scancode == 0x01d) || (scancode == 0x11d)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_pgup && (recv_lalt || recv_ralt) && (!kbd_req_capture || mouse_capture)) { + /* We received an CTRL while ALT+Page Up was pressed, while the mouse + is not captured, suppress the ALT and send a TAB key up. */ + if (recv_lctrl) { + keyboard_input(0, 0x01d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x01d); + keyboard_input(0, 0x01d); + recv_lctrl = 0; + } + if (recv_rctrl) { + keyboard_input(0, 0x11d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x11d); + keyboard_input(0, 0x11d); + recv_rctrl = 0; + } + keyboard_input(0, 0x149); + recv_pgup = 0; } else { switch (scancode) { - case 0x00F: + case 0x00f: recv_tab = !(rawKB.Flags & RI_KEY_BREAK); break; + case 0x01d: + recv_lctrl = !(rawKB.Flags & RI_KEY_BREAK); + break; + case 0x049: + recv_npgup = !(rawKB.Flags & RI_KEY_BREAK); + break; case 0x038: recv_lalt = !(rawKB.Flags & RI_KEY_BREAK); break; + case 0x11d: + recv_rctrl = !(rawKB.Flags & RI_KEY_BREAK); + break; case 0x138: recv_ralt = !(rawKB.Flags & RI_KEY_BREAK); break; + case 0x149: + recv_pgup = !(rawKB.Flags & RI_KEY_BREAK); + break; } /* Translate right CTRL to left ALT if the user has so chosen. */ - if ((scancode == 0x11D) && rctrl_is_lalt) + if ((scancode == 0x11d) && rctrl_is_lalt) scancode = 0x038; /* Normal scan code pass through, pass it through as is if diff --git a/src/win/win_keyboard.c b/src/win/win_keyboard.c index 6b7e00b57..71acbf28b 100644 --- a/src/win/win_keyboard.c +++ b/src/win/win_keyboard.c @@ -107,7 +107,8 @@ void keyboard_handle(PRAWINPUT raw) { USHORT scancode; - static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0; + static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0, recv_lctrl = 0, recv_rctrl = 0; + static int recv_npgup = 0, recv_pgup = 0; RAWKEYBOARD rawKB = raw->data.keyboard; scancode = rawKB.MakeCode; @@ -133,7 +134,7 @@ keyboard_handle(PRAWINPUT raw) We use scan code 0xFFFF to mean a mapping that has a prefix other than E0 and that is not E1 1D, which is, for our purposes, invalid. */ - if ((scancode == 0x00F) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && !mouse_capture) { + if ((scancode == 0x00f) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && (!kbd_req_capture || mouse_capture)) { /* We received a TAB while ALT was pressed, while the mouse is not captured, suppress the TAB and send an ALT key up. */ if (recv_lalt) { @@ -152,27 +153,158 @@ keyboard_handle(PRAWINPUT raw) keyboard_input(0, 0x138); recv_ralt = 0; } - } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_tab && !mouse_capture) { + } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_tab && (!kbd_req_capture || mouse_capture)) { /* We received an ALT while TAB was pressed, while the mouse is not captured, suppress the ALT and send a TAB key up. */ - keyboard_input(0, 0x00F); + keyboard_input(0, 0x00f); recv_tab = 0; + } else if (((scancode == 0x049) || (scancode == 0x149)) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && (recv_lctrl || recv_rctrl) && (!kbd_req_capture || mouse_capture)) { + /* We received a NumPad Page Up or Page Up while CTRL+ALT was pressed, while the keyboard + is captured, suppress the Page Up and send an CTRL+ALT key up. */ + if (recv_lctrl) { + keyboard_input(0, 0x01d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x01d); + keyboard_input(0, 0x01d); + recv_lctrl = 0; + } + if (recv_rctrl) { + keyboard_input(0, 0x11d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x11d); + keyboard_input(0, 0x11d); + recv_rctrl = 0; + } + if (recv_lalt) { + keyboard_input(0, 0x038); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x038); + keyboard_input(0, 0x038); + recv_lalt = 0; + } + if (recv_ralt) { + keyboard_input(0, 0x138); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x138); + keyboard_input(0, 0x138); + recv_ralt = 0; + } + } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_npgup && (recv_lctrl || recv_rctrl) && (!kbd_req_capture || mouse_capture)) { + /* We received an ALT while CTRL+NumPad Page Up was pressed, while the mouse + is not captured, suppress the ALT and send a TAB key up. */ + if (recv_lctrl) { + keyboard_input(0, 0x01d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x01d); + keyboard_input(0, 0x01d); + recv_lctrl = 0; + } + if (recv_rctrl) { + keyboard_input(0, 0x11d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x11d); + keyboard_input(0, 0x11d); + recv_rctrl = 0; + } + keyboard_input(0, 0x049); + recv_npgup = 0; + } else if (((scancode == 0x01d) || (scancode == 0x11d)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_npgup && (recv_lalt || recv_ralt) && (!kbd_req_capture || mouse_capture)) { + /* We received an CTRL while ALT+NumPad Page Up was pressed, while the mouse + is not captured, suppress the ALT and send a TAB key up. */ + if (recv_lalt) { + keyboard_input(0, 0x038); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x038); + keyboard_input(0, 0x038); + recv_lalt = 0; + } + if (recv_ralt) { + keyboard_input(0, 0x138); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x138); + keyboard_input(0, 0x138); + recv_ralt = 0; + } + keyboard_input(0, 0x049); + recv_npgup = 0; + } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_pgup && (recv_lctrl || recv_rctrl) && (!kbd_req_capture || mouse_capture)) { + /* We received an ALT while CTRL+Page Up was pressed, while the mouse + is not captured, suppress the ALT and send a TAB key up. */ + if (recv_lalt) { + keyboard_input(0, 0x038); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x038); + keyboard_input(0, 0x038); + recv_lalt = 0; + } + if (recv_ralt) { + keyboard_input(0, 0x138); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x138); + keyboard_input(0, 0x138); + recv_ralt = 0; + } + keyboard_input(0, 0x149); + recv_pgup = 0; + } else if (((scancode == 0x01d) || (scancode == 0x11d)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_pgup && (recv_lalt || recv_ralt) && (!kbd_req_capture || mouse_capture)) { + /* We received an CTRL while ALT+Page Up was pressed, while the mouse + is not captured, suppress the ALT and send a TAB key up. */ + if (recv_lctrl) { + keyboard_input(0, 0x01d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x01d); + keyboard_input(0, 0x01d); + recv_lctrl = 0; + } + if (recv_rctrl) { + keyboard_input(0, 0x11d); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x11d); + keyboard_input(0, 0x11d); + recv_rctrl = 0; + } + keyboard_input(0, 0x149); + recv_pgup = 0; } else { switch (scancode) { - case 0x00F: + case 0x00f: recv_tab = !(rawKB.Flags & RI_KEY_BREAK); break; + case 0x01d: + recv_lctrl = !(rawKB.Flags & RI_KEY_BREAK); + break; + case 0x049: + recv_npgup = !(rawKB.Flags & RI_KEY_BREAK); + break; case 0x038: recv_lalt = !(rawKB.Flags & RI_KEY_BREAK); break; + case 0x11d: + recv_rctrl = !(rawKB.Flags & RI_KEY_BREAK); + break; case 0x138: recv_ralt = !(rawKB.Flags & RI_KEY_BREAK); break; + case 0x149: + recv_pgup = !(rawKB.Flags & RI_KEY_BREAK); + break; } /* Translate right CTRL to left ALT if the user has so chosen. */ - if ((scancode == 0x11D) && rctrl_is_lalt) + if ((scancode == 0x11d) && rctrl_is_lalt) scancode = 0x038; /* Normal scan code pass through, pass it through as is if