Switched back to raw input - it appears it *does* work with the hook.

This commit is contained in:
OBattler 2025-01-03 00:15:28 +01:00
parent 7ad3b81058
commit 06923a2800
4 changed files with 19 additions and 50 deletions

View file

@ -206,7 +206,7 @@ int video_fullscreen_scale_maximized = 0; /* (C) Whether
also apply when maximized. */
int do_auto_pause = 0; /* (C) Auto-pause the emulator on focus
loss */
int raw_input = 0; /* (C) Use raw input */
int hook_enabled = 1; /* (C) Keyboard hook is enabled */
char uuid[MAX_UUID_LEN] = { '\0' }; /* (C) UUID or machine identifier */
int other_ide_present = 0; /* IDE controllers from non-IDE cards are
@ -453,6 +453,8 @@ delete_nvr_file(uint8_t flash)
fn = NULL;
}
extern void device_find_all_descs(void);
/*
* Perform initial startup of the PC.
*
@ -562,7 +564,7 @@ usage:
printf("-S or --settings - show only the settings dialog\n");
#endif
printf("-V or --vmname name - overrides the name of the running VM\n");
printf("-W or --raw - uses raw input (compatibility-only outside Windows)\n");
printf("-W or --nohook - disables keyboard hook (compatibility-only outside Windows)\n");
printf("-X or --clear what - clears the 'what' (cmos/flash/both)\n");
printf("-Y or --donothing - do not show any UI or run the emulation\n");
printf("-Z or --lastvmpath - the last parameter is VM path rather than config\n");
@ -638,8 +640,8 @@ usage:
dump_missing = 1;
} else if (!strcasecmp(argv[c], "--donothing") || !strcasecmp(argv[c], "-Y")) {
do_nothing = 1;
} else if (!strcasecmp(argv[c], "--raw") || !strcasecmp(argv[c], "-W")) {
raw_input = 1;
} else if (!strcasecmp(argv[c], "--nohook") || !strcasecmp(argv[c], "-W")) {
hook_enabled = 0;
} else if (!strcasecmp(argv[c], "--keycodes") || !strcasecmp(argv[c], "-K")) {
if ((c + 1) == argc)
goto usage;

View file

@ -165,7 +165,7 @@ extern _Atomic double mouse_y_error; /* Mouse error accumulator - Y */
#endif
extern int pit_mode; /* (C) force setting PIT mode */
extern int fm_driver; /* (C) select FM sound driver */
extern int raw_input; /* (C) Use raw input */
extern int hook_enabled; /* (C) Keyboard hook is enabled */
/* Keyboard variables for future key combination redefinition. */
extern uint16_t key_prefix_1_1;

View file

@ -43,6 +43,7 @@ Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin)
#endif
#ifdef Q_OS_WINDOWS
# include "qt_rendererstack.hpp"
# include "qt_winrawinputfilter.hpp"
# include "qt_winmanagerfilter.hpp"
# include <86box/win.h>
@ -143,50 +144,20 @@ keyboard_getkeymap()
}
}
static void
kbd_handle(uint16_t scancode, uint16_t flags)
{
if (flags & LLKHF_EXTENDED)
scancode |= 0x100;
/* Translate the scan code to 9-bit */
scancode = convert_scan_code(scancode);
/* Remap it according to the list from the Registry */
if ((scancode < (sizeof(scancode_map) / sizeof(scancode_map[0]))) && (scancode != scancode_map[scancode])) {
// pclog("Scan code remap: %03X -> %03X\n", scancode, scancode_map[scancode]);
scancode = scancode_map[scancode];
}
/* If it's not 0xFFFF, send it to the emulated
keyboard.
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. */
/* Translate right CTRL to left ALT if the user has so
chosen. */
if ((scancode == 0x11d) && rctrl_is_lalt)
scancode = 0x038;
/* Normal scan code pass through, pass it through as is if
it's not an invalid scan code. */
if (scancode != 0xFFFF)
keyboard_input(!(flags & LLKHF_UP), scancode);
main_window->checkFullscreenHotkey();
}
static LRESULT CALLBACK
emu_LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
LPKBDLLHOOKSTRUCT lpKdhs = (LPKBDLLHOOKSTRUCT) lParam;
/* Checks if CTRL was pressed. */
BOOL bCtrlDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);
BOOL is_over_window = (GetForegroundWindow() == ((HWND) main_window->winId()));
if ((GetForegroundWindow() == ((HWND) main_window->winId())) && !(lpKdhs->scanCode & 0xff00))
kbd_handle(lpKdhs->scanCode, lpKdhs->flags);
if (show_second_monitors) for (int monitor_index = 1; monitor_index < MONITORS_NUM; monitor_index++) {
const auto &secondaryRenderer = main_window->renderers[monitor_index];
is_over_window = is_over_window && (GetForegroundWindow() == ((HWND) secondaryRenderer->winId()));
}
if ((nCode < 0) || (nCode != HC_ACTION) || (!mouse_capture && !video_fullscreen))
if ((nCode < 0) || (nCode != HC_ACTION)/* || (!mouse_capture && !video_fullscreen)*/ || !is_over_window)
return CallNextHookEx(NULL, nCode, wParam, lParam);
else if ((lpKdhs->scanCode == 0x01) && (lpKdhs->flags & LLKHF_ALTDOWN) &&
!(lpKdhs->flags & (LLKHF_UP | LLKHF_EXTENDED)))
@ -480,7 +451,7 @@ main(int argc, char *argv[])
/* Force raw input if a debugger is present. */
if (IsDebuggerPresent()) {
pclog("WARNING: Debugged detected, forcing raw input\n");
raw_input = 1;
hook_enabled = 0;
}
/* Setup raw input */
@ -547,7 +518,8 @@ main(int argc, char *argv[])
});
#ifdef Q_OS_WINDOWS
if (!raw_input) {
if (hook_enabled) {
/* Yes, low-level hooks *DO* work raw input, at least global ones. */
llhook = SetWindowsHookEx(WH_KEYBOARD_LL, emu_LowLevelKeyboardProc, NULL, 0);
atexit([] () -> void {
if (llhook)

View file

@ -64,9 +64,7 @@ WindowsRawInputFilter::Register(MainWindow *window)
.hwndTarget = nullptr}
};
if (raw_input && (RegisterRawInputDevices(rid, 2, sizeof(rid[0])) == FALSE))
return std::unique_ptr<WindowsRawInputFilter>(nullptr);
else if (!raw_input && RegisterRawInputDevices(&(rid[1]), 1, sizeof(rid[0])) == FALSE)
if (RegisterRawInputDevices(rid, 2, sizeof(rid[0])) == FALSE)
return std::unique_ptr<WindowsRawInputFilter>(nullptr);
std::unique_ptr<WindowsRawInputFilter> inputfilter(new WindowsRawInputFilter(window));
@ -97,10 +95,7 @@ WindowsRawInputFilter::~WindowsRawInputFilter()
.hwndTarget = NULL}
};
if (raw_input)
RegisterRawInputDevices(rid, 2, sizeof(rid[0]));
else
RegisterRawInputDevices(&(rid[1]), 1, sizeof(rid[0]));
RegisterRawInputDevices(rid, 2, sizeof(rid[0]));
}
bool