aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/term.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/term.c b/src/term.c
index 6927bd9..0325208 100644
--- a/src/term.c
+++ b/src/term.c
@@ -908,7 +908,18 @@ static int lst_readkey(lua_State *L) {
908 } 908 }
909 909
910 wchar_t wc = _getwch(); 910 wchar_t wc = _getwch();
911 // printf("----\nread wchar_t: %x\n", wc); 911 // printf("----\nread wchar_t: %x\n", (unsigned int)wc);
912
913 if (wc == 0x00 || wc == 0xE0) {
914 // printf("Ignoring scan code: %x\n", (unsigned int)wc);
915 // On Windows, especially with key-repeat, we can get native scancodes even if we've set the console
916 // to ANSI mode. Something, something, terminal not keeping up... These are not valid wide characters,
917 // so we ignore them. Scan codes start with either 0x00 or 0xE0, and have a follow up byte, which we all ignore.
918 // These codes are unique, so we do not risk dropping valid data.
919 _getwch(); // Discard 2nd half of the scan code
920 return 0;
921 }
922
912 if (wc == WEOF) { 923 if (wc == WEOF) {
913 lua_pushnil(L); 924 lua_pushnil(L);
914 lua_pushliteral(L, "read error"); 925 lua_pushliteral(L, "read error");
@@ -929,7 +940,7 @@ static int lst_readkey(lua_State *L) {
929 } 940 }
930 941
931 wchar_t wc2 = _getwch(); 942 wchar_t wc2 = _getwch();
932 // printf("read wchar_t 2: %x\n", wc2); 943 // printf("read wchar_t 2: %x\n", (unsigned int)wc2);
933 if (wc2 == WEOF) { 944 if (wc2 == WEOF) {
934 lua_pushnil(L); 945 lua_pushnil(L);
935 lua_pushliteral(L, "read error"); 946 lua_pushliteral(L, "read error");