bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix backspace key in Windows console driver


From: Pavel Fedin
Subject: [PATCH] Fix backspace key in Windows console driver
Date: Fri, 23 Jun 2023 00:08:38 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

 Hello everyone!

Windows console reports both VK_BACK and an ASCII code of 0x7F (DEL) via native API. The driver always prefers ASCII code if present, therefore a wrong code is reported to the app.

I made this patch to fix it, i hope you find it useful.

diff -ru ncurses-6.4-20230211/ncurses/win32con/win_driver.c ncurses-6.4-20230211-fixed/ncurses/win32con/win_driver.c --- ncurses-6.4-20230211/ncurses/win32con/win_driver.c 2023-02-12 03:31:33 +0000 +++ ncurses-6.4-20230211-fixed/ncurses/win32con/win_driver.c 2023-06-10 23:24:54 +0000
@@ -94,7 +94,8 @@
     GenMap(VK_RIGHT, KEY_RIGHT),
     GenMap(VK_DOWN, KEY_DOWN),
     GenMap(VK_DELETE, KEY_DC),
-    GenMap(VK_INSERT, KEY_IC)
+    GenMap(VK_INSERT, KEY_IC),
+    GenMap(VK_BACK, KEY_BACKSPACE)
 };
 static const LONG ansi_keys[] =
 {
@@ -1570,7 +1571,12 @@
                 char ch = inp_rec.Event.KeyEvent.uChar.AsciiChar;

                 if (inp_rec.Event.KeyEvent.bKeyDown) {
-                    if (0 == ch) {
+                    /*
+                      * Windows console reports VK_BACK together with an ASCII +                      * character 0x7F (DEL), we we have to prefer VK in this case
+                      * in order to report a correct event to an app.
+                      */
+                    if (0 == ch || vk == VK_BACK) {
                     int nKey = MapKey(vk);
                     if (nKey < 0) {
                         CONSUME();
@@ -2135,7 +2141,7 @@
             vk = (WORD) (vk + 12);
             }
         }
-        if (*buf == 0) {
+        if (*buf == 0 || vk == VK_BACK) {
             int key = MapKey(vk);
             if (key < 0)
             continue;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]