From 793556fff386a9c7003e59618af1e062fd36c46a Mon Sep 17 00:00:00 2001 From: William McBrine Date: Wed, 12 May 2021 16:02:48 -0400 Subject: [PATCH] Make wincon's PDC_set_keyboard_binary() actually work; retain processed input mode status if not explicitly set. In other words, ^C will cause a SIGINT in non-raw mode. (This matches the behavior of OS/2 and some versions of DOS -- others need fixing.) Suggested by https://stackoverflow.com/questions/67276939/ To Do: Some other console attributes are currently ignored, but could be used. --- wincon/pdckbd.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/wincon/pdckbd.c b/wincon/pdckbd.c index d2c3ab69..fc634502 100644 --- a/wincon/pdckbd.c +++ b/wincon/pdckbd.c @@ -215,7 +215,13 @@ static KPTAB ext_kptab[] = void PDC_set_keyboard_binary(bool on) { + DWORD mode; + PDC_LOG(("PDC_set_keyboard_binary() - called\n")); + + GetConsoleMode(pdc_con_in, &mode); + SetConsoleMode(pdc_con_in, !on ? (mode | ENABLE_PROCESSED_INPUT) : + (mode & ~ENABLE_PROCESSED_INPUT)); } /* check if a key or mouse event is waiting */ @@ -635,13 +641,17 @@ bool PDC_has_mouse(void) int PDC_mouse_set(void) { - /* If turning on mouse input: Set ENABLE_MOUSE_INPUT, and clear - all other flags, including the extended flags; - If turning off the mouse: Set QuickEdit Mode to the status it - had on startup, and clear all other flags */ + DWORD mode; - SetConsoleMode(pdc_con_in, SP->_trap_mbe ? - (ENABLE_MOUSE_INPUT|0x0088) : (pdc_quick_edit|0x0088)); + /* If turning on mouse input: Set ENABLE_MOUSE_INPUT, and clear + all other flags, except processed input mode; + If turning off the mouse: Set QuickEdit Mode to the status it + had on startup, and clear all other flags, except etc. */ + + GetConsoleMode(pdc_con_in, &mode); + mode = (mode & 1) | 0x0088; + SetConsoleMode(pdc_con_in, mode | (SP->_trap_mbe ? + ENABLE_MOUSE_INPUT : pdc_quick_edit)); memset(&old_mouse_status, 0, sizeof(old_mouse_status));