final_game_tech icon indicating copy to clipboard operation
final_game_tech copied to clipboard

Umlaut characters / Shifted keys / Emoji mapping?

Open KungPhoo opened this issue 9 months ago • 2 comments

Hi,

awesome work you did! When polling events, and pressing Shift+2, I get event.keyboard.keyCode = 50, which is '2'. However, I was expecting the quote '"' 0x22 code, instead. Did I do anything wrong? Also, the emoji keyboard in Windows has no effect. Here's how to implement that, if it helps.

        static wchar_t highSurrogate = 0;  // Store high surrogate if needed
        ReadConsoleInputW(hStdin, &inputRecord, 1, &eventsRead);
        if (inputRecord.EventType == KEY_EVENT && inputRecord.Event.KeyEvent.bKeyDown) {
            WCHAR ch = inputRecord.Event.KeyEvent.uChar.UnicodeChar;
                // Detect surrogate pairs
                if (ch >= 0xD800 && ch <= 0xDBFF) {
                    // It's a high surrogate, store it
                    highSurrogate = ch;
                    continue;
                } else if (ch >= 0xDC00 && ch <= 0xDFFF && highSurrogate != 0) {
                    // It's a low surrogate, combine with high surrogate
                    key.printable = (ch != 0);
                    uint32_t fullCodePoint = ((highSurrogate - 0xD800) << 10) + (ch - 0xDC00) + 0x10000;
                    key.code = fullCodePoint;
                    highSurrogate = 0;  // Reset high surrogate storage
                } else {
                    key.code = ch;
                    highSurrogate = 0;  // Reset in case of an unexpected sequence
                }
                break;
            }
            putToKeyboardBuffer(key);
        }

KungPhoo avatar Mar 06 '25 06:03 KungPhoo