diff --git a/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c b/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c index 7d12bc904..ff477f2a0 100644 --- a/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c +++ b/src/3rdparty/win32_src/pdcurses/wingui/pdcscrn.c @@ -1921,27 +1921,7 @@ static LRESULT ALIGN_STACK CALLBACK WndProc (const HWND hwnd, exit( 0); if( wParam != 9 || !(GetKeyState( VK_SHIFT) & 0x8000)) if (!key_already_handled || last_key_handled != (int)wParam) { -#if _UNICODE - /* if we are building against the unicode runtime, key messages - received by WM_CHAR will be UTF16 encoded; convert it to a - sequence UTF8 bytes and inject them one at a time. - see: https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-char */ - wchar_t utf16[3]; /* may be a surrogate pair */ - utf16[0] = LOWORD(wParam); - utf16[1] = HIWORD(wParam); - utf16[2] = 0; - unsigned char utf8[4 + 4 + 1]; - int size = WideCharToMultiByte(CP_UTF8, 0, utf16, -1, 0, 0, 0, 0); - if (size > 0 && sizeof(utf8)) { - utf8[0] = 0; - WideCharToMultiByte(CP_UTF8, 0, utf16, -1, utf8, size, 0, 0); - for (int i = 0; i < size - 1; i++) { - add_key_to_queue((int) utf8[i]); - } - } -#else add_key_to_queue((int)wParam); -#endif } key_already_handled = FALSE; last_key_handled = 0; diff --git a/src/musikcube/cursespp/Text.cpp b/src/musikcube/cursespp/Text.cpp index c426d08b1..28daf3cbc 100755 --- a/src/musikcube/cursespp/Text.cpp +++ b/src/musikcube/cursespp/Text.cpp @@ -331,13 +331,23 @@ namespace cursespp { kn = std::string("M-") + std::string(keyname((int)next)); } } - #ifdef WIN32 +#ifdef WIN32 /* transform alt->meta for uniform handling */ else if (kn.find("ALT_") == 0) { std::transform(kn.begin(), kn.end(), kn.begin(), tolower); kn.replace(0, 4, "M-"); } - #endif +#endif +#if defined WIN32 && defined _UNICODE + else if (kn.find("KEY_") == std::string::npos && + kn.find("CTL_") == std::string::npos && + kn.find("^") != 0) + { + /* on Windows if _UNICODE is defined then ch will contain a UTF16 + encoded character; transform it to UTF8. */ + kn = u16to8(std::wstring(1, (wchar_t) ch)); + } +#else /* multi-byte UTF8 character */ else if (ch >= 194 && ch <= 223) { kn = ""; @@ -357,19 +367,10 @@ namespace cursespp { kn += (char) getch(); kn += (char) getch(); } +#endif kn = Normalize(kn); -#ifdef WIN32 - /* seems like on Windows using PDCurses, if a non-English keyboard - is selected (like Russian) we receive a UTF16 character, not an - encoded UTF8 character. in this case, let's convert it to a UTF8 - string and return that. */ - if (kn == "UNKNOWN KEY" && ch > 244) { - kn = u16to8(std::wstring(1, (wchar_t)ch)); - } -#endif - // std::cerr << "keyname: " << kn << std::endl; // std::cerr << "ch: " << ch << std::endl;