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

Fix #8930: [Win32] Don't handle printable keys on keydown if an edit box is in focus. #8976

Merged
merged 1 commit into from Apr 9, 2021

Conversation

@michicc
Copy link
Member

@michicc michicc commented Apr 8, 2021

Motivation / Problem

On Windows, printable input for text input is handled by WM_CHAR messages.
The WM_KEYDOWN handler tries to predict if a keydown will be followed by WM_CHAR message to do the right thing, but this prediction can fail if IMEs are in play. This can lead to duplicate text input.

Description

If a key press is in fact printable text, it will result in a WM_CHAR (or a WM_IME_*) message. If no WM_CHAR follows, it is not printable text. As such, handle printable input only on the WM_CHAR message. Without an edit box, do the handling in keydown as usual to support hotkeys.

Limitations

I only tested normal German/latin input and the japanese IME. Some other IMEs or strange keyboard layouts might behave differently.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
…n edit box is in focus.

Handle printable input only when the matching WM_CHAR message is incoming.
Without an edit box, do the handling in keydown as usual to support hotkeys.
nielsmh
nielsmh approved these changes Apr 9, 2021
Copy link
Contributor

@nielsmh nielsmh left a comment

Fixes the issue by my own testing. There's still some weird delays in input when using IME and typing too fast, but not a problem during regular use.

@michicc
Copy link
Member Author

@michicc michicc commented Apr 9, 2021

The delay might be because we don't wait on messages, so if the IME takes a bit to post the WM_CHAR message, we might take a trip through drawing first.

@michicc michicc merged commit 96d33ab into OpenTTD:master Apr 9, 2021
12 checks passed
@michicc michicc deleted the pr/fix_8930 branch Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants