Skip to content

Fix non-ASCII keyboard input#3199

Merged
LeftofZen merged 8 commits intoOpenLoco:masterfrom
LeeSpork:fix-non-ascii-input
Aug 19, 2025
Merged

Fix non-ASCII keyboard input#3199
LeftofZen merged 8 commits intoOpenLoco:masterfrom
LeeSpork:fix-non-ascii-input

Conversation

@LeeSpork
Copy link
Copy Markdown
Contributor

@LeeSpork LeeSpork commented Aug 14, 2025

Fixes #3198

It feels kind of stupid, both to be using a module named localization here, as well as the crazy cast, but it works.

Previously the behaviour was bugged such that ä would become {keyCode=228 charCode=4294967235} instead of {keyCode=228 charCode=228}.

@LeeSpork
Copy link
Copy Markdown
Contributor Author

image

@LeeSpork
Copy link
Copy Markdown
Contributor Author

I updated this to also use the convertUnicodeToLoco function. This allows the user to also type Polish characters such as Łłżńść. It also means that characters that are not supported will become "?" instead of simply being ignored by TextInput.cpp's handleInput function, resulting in a more responsive user experience (in the case of someone mistakenly using a keyboard layout with unsupported characters). (This is different from original Locomotion (Steam) behaviour, where typing Greek letters instead results in mojibake).
image

}

uint32_t index = _keyQueueLastWrite;
_keyQueue[index].charCode = Localisation::convertUnicodeToLoco(Localisation::readCodePoint((unsigned char**)&text));
Copy link
Copy Markdown
Contributor

@duncanspumpkin duncanspumpkin Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use c style casts in this code base. readCodePoint should be taking a const utf8_t** (but its not so please correct that) so that this call becomes readCodePoint(static_cast<utf8_t**>(&text))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static_cast does not work here, I think because of the conversion from signed to unsigned. Using reinterpret_cast works, but I decided to still use unsigned char in my new changes, as I am not sure if it would be best practise to reinterpret directly to utf8_t? Thank you for your patience.

}

uint32_t index = _keyQueueLastWrite;
auto unsignedText = reinterpret_cast<const unsigned char*>(text);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you at least use uint8_t instead of unsigned char since that is what we use throughout the codebase.

@LeftofZen LeftofZen enabled auto-merge (squash) August 19, 2025 00:02
@LeftofZen LeftofZen merged commit c4625f7 into OpenLoco:master Aug 19, 2025
10 checks passed
@duncanspumpkin duncanspumpkin added this to the v25.07+ milestone Aug 20, 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

Successfully merging this pull request may close these issues.

Cannot write non-English letters in text boxes

3 participants