From 168910b72ff1820a2524b642496483a910ecc81b Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 26 Feb 2025 11:39:04 +0600 Subject: [PATCH] All held-down keys are now released when Alt-Tab'ing out Only applies when Raw Input is in use on Windows --- src/device/keyboard.c | 14 ++++++++++++++ src/include/86box/keyboard.h | 1 + src/qt/qt_mainwindow.cpp | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/device/keyboard.c b/src/device/keyboard.c index 582dcf0b1..58d5a4724 100644 --- a/src/device/keyboard.c +++ b/src/device/keyboard.c @@ -332,6 +332,20 @@ keyboard_input(int down, uint16_t scan) } } +void +keyboard_all_up(void) +{ + for (unsigned short i = 0; i < 0x200; i++) { + if (recv_key_ui[i]) { + recv_key_ui[i] = 0; + } + if (recv_key[i]) { + recv_key[i] = 0; + key_process(i, 0); + } + } +} + static uint8_t keyboard_do_break(uint16_t scan) { diff --git a/src/include/86box/keyboard.h b/src/include/86box/keyboard.h index ec5c05775..110e4f760 100644 --- a/src/include/86box/keyboard.h +++ b/src/include/86box/keyboard.h @@ -269,6 +269,7 @@ extern void keyboard_poll_host(void); extern void keyboard_process(void); extern uint16_t keyboard_convert(int ch); extern void keyboard_input(int down, uint16_t scan); +extern void keyboard_all_up(void); extern void keyboard_update_states(uint8_t cl, uint8_t nl, uint8_t sl); extern uint8_t keyboard_get_shift(void); extern void keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl); diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 3ee58f23b..62ac94f30 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -277,6 +277,8 @@ MainWindow::MainWindow(QWidget *parent) if (mouse_capture) emit setMouseCapture(false); + keyboard_all_up(); + if (do_auto_pause && !dopause) { auto_paused = 1; plat_pause(1);