Skip to content

Conversation

daxian-dbw
Copy link
Member

Use a heuristic check to determine if a key pressing is a dead key. Fix #914

The Win32 API ToUnicode doesn't work well with non-natively-supported keyboard layouts, such as the Neo keyboard layout. ToUnicode maps Neo dead keys to unicode characters incorrectly and results in PSReadLine rendering the dead keys.

@daxian-dbw
Copy link
Member Author

daxian-dbw commented Jun 15, 2019

@Snaptags this fix seems to be working fine with Neo. Can you please give it another try?

@Snaptags
Copy link

Dead key handling is working perfectly! Thank you for this great fix.

@daxian-dbw
Copy link
Member Author

Thanks @Snaptags for trying it out.
@lzybkr can you please review this fix? Thanks!

// We got an 'OemXXX' ConsoleKey, '\0' key char, and no 'Ctrl' modifier. It's very likely generated by a dead key.
// We check for 'Ctrl' modifier because it's easy to generate '\0' KeyChar and 'OemXXX' by combinding 'Ctrl' with
// another special key, such as 'Ctrl+?' and 'Ctrl+;'.
isDeadKey = (c == '\0') && (consoleKey >= ConsoleKey.Oem1 && consoleKey <= ConsoleKey.Oem102) && !isCtrl;
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a large gap of invalid values in that range - maybe you should use a switch?
You also miss OemClear in that range.

Copy link
Member Author

Choose a reason for hiding this comment

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

I only see the OemXXX ConsoleKeys generated for the dead keys that I have inspected so far ... Yes, OemClear is not in that range. I didn't include it only because I didn't see it was generated by the dead keys I have inspected :) I will keep the check as is for now, and change it as needed when there are new dead-key issue reported.

@daxian-dbw
Copy link
Member Author

Test run passed with French keyboard layout:

image

@daxian-dbw daxian-dbw merged commit f2f5531 into PowerShell:master Jun 17, 2019
@daxian-dbw daxian-dbw deleted the neo-fix branch June 17, 2019 20:38
@daxian-dbw daxian-dbw added this to the 2.0.0-beta5 milestone Sep 13, 2019
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.

Beta 4: problems with dead keys and custom keyboard layout (Neo2)
3 participants