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.
Copy link
Contributor

@nielsmh nielsmh left a comment

Choose a reason for hiding this comment

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

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.

@nielsmh nielsmh added the backport requested This PR should be backport to current release (RC / stable) label Apr 9, 2021
@michicc
Copy link
Member Author

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
@michicc michicc deleted the pr/fix_8930 branch April 9, 2021 10:24
@LordAro LordAro added backported This PR is backported to a current release (RC / stable) and removed backport requested This PR should be backport to current release (RC / stable) labels Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR is backported to a current release (RC / stable)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants