Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Umlaut characters / Shifted keys / Emoji mapping? #165

Open
KungPhoo opened this issue Mar 6, 2025 · 2 comments
Open

Umlaut characters / Shifted keys / Emoji mapping? #165

KungPhoo opened this issue Mar 6, 2025 · 2 comments

Comments

@KungPhoo
Copy link

KungPhoo commented Mar 6, 2025

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);
        }
@f1nalspace
Copy link
Owner

f1nalspace commented Mar 6, 2025

Thanks!

You are right, i never implemented shift/ctrl/alt handling in combination with a key event, because key events are for a single key.
But you can check the "modifiers" field from the keyboard event and handle the required Quotes/Umlaute characters manually.

Or better, use the keyboard event "fplKeyboardEventType_Input" instead, then the mapping should work correctly.
You can see how it works in the FPL_Input demo.

@KungPhoo
Copy link
Author

KungPhoo commented Mar 7, 2025

Thanks. That did the trick for me.

        if (event.type == fplEventType_Keyboard) {
            keyPress.code = uint32_t(event.keyboard.keyCode);
            // printable character
            if (event.keyboard.type == fplKeyboardEventType_Input) {
                keyPress.printable = true;
                putToKeyboardBuffer(keyPress);
                lastCharPress = keyPress;
            // key repeat
            } else if (event.keyboard.type == fplKeyboardEventType_Button && event.keyboard.buttonState == fplButtonState_Repeat) {
                if (lastCharPress.code != 0) {
                    putToKeyboardBuffer(lastCharPress);
                }
            // non printable characters
            } else if (event.keyboard.type == fplKeyboardEventType_Button && event.keyboard.buttonState == fplButtonState_Press) {
                keyPress.code = 0;
                keyPress.printable = false;
                switch (event.keyboard.keyCode) {
                case fplKey_Delete:   keyPress.code = uint32_t(KeyConstant::DEL); repeatable = true; break;
                case fplKey_F1:       keyPress.code = uint32_t(KeyConstant::F1); break;
                case fplKey_Up:       keyPress.code = uint32_t(KeyConstant::CRSR_UP);  repeatable = true; break;
                case fplKey_Down:     keyPress.code = uint32_t(KeyConstant::CRSR_DOWN);  repeatable = true; break;
                // ...
                }
                if (keyPress.code != 0) {
                    putToKeyboardBuffer(keyPress);
                    if (repeatable) {
                        lastCharPress = keyPress;
                    } else {
                        lastCharPress.code = 0;
                    }
                }
            }
        }

I started a question on StackOverflow, because I don't get any WM_xx message when I use the emoji keyboard, so keep this issue open, please.

@f1nalspace f1nalspace changed the title Umlaut characters / Shifted keys? Umlaut characters / Shifted keys / Emoji mapping? Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants