-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Fixed #3101: Alt+Arrow-Keys print extra characters #3117
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
OK. I went to read the source code for the input code deep behind The arrow keys in the cluster of four have the same scan codes from the keyboard as the arrow keys on the numpad 2, 4, 6, 8. When the 0 bit is unset in the If we look at https://en.wikipedia.org/wiki/Code_page_437... we can see that the symbols on 2, 4, 6, and 8 respectively were ☻♦♠◘. So it's faithfully mapping them as if you entered them on the numpad. When the 0 bit is set in So committing this fix will fix the extra characters coming out... but it will probably also end up breaking things like numpad Alt+1+3+7 becomes |
Thank you so much for looking into this! And just in case you do have the time: Should we keep setting the 2nd bit in I don't think the missing input of Alt codes will be large issue for now though. On the other hand the fact that we're probably not handling cases where |
The PR is generally ready to be merged from my side. |
The 2nd bit is about dead keys. If it is off, then when you start a dead key combination, some state about the dead key is persisted in the keyboard layout state until the next call. If it is on, then it will skip the persistence phase as it processes the potential dead key. (That's my 2 minute read of it... it's massively complex. If you need further than that, let me know.) |
@miniksa I had a bit time just now and debugged this part of the code.
To fix the latter tangential issue, I'd like to propose that we simply return the first character of the output buffer, if the return value of |
Yeah, sure. Until proven otherwise, I'm fine to leave the other bit on.
Sorry, on which keyboard layout are we talking? My understanding of "dead keys" was like the US-International keyboard where you press/release ' then press/release e to get é. I think pressAltGr + press e then release both chorded on European keyboards is supposed to fire immediately... is that also called a "dead key" combo? This is also the behavior/return codes that I would expect to change with and without the 2 bit set in the flags field. Does it not change? From what I'm reading internally... As long as both of them yield the same result as typing into something like
That sounds reasonable based on the analysis above. |
Sounds like this PR does what it set out to do. Are there any other questions? |
Sorry, I felt like the discussion with @lhecker wasn't 100% complete. But re-reviewing it, I think I just need to file a follow on task for the >1 thing and then get this merged. |
And I forgot about this PR. 😅 |
No problem, thank you for your efforts anyway. I did file #3554 just now to follow on from this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing the rest of the discussion, this seems fine by me. Thanks!
🎉 Handy links: |
Summary of the Pull Request
This PR potentially fixes #3101.
PR Checklist
Detailed Description of the Pull Request / Additional comments
This PR fixes #3101 by setting flag 0 in
ToUnicodeEx()
even though the documentation says "If bit 0 is set, a menu is active.". I'm not 100% sure why it works, but it definitely does in this case.I thought that bit 2, which claims that "keyboard state is not changed" would be sufficient to prevent this from happening, but it seems that's not the case.
I believe this PR should be verified by a developer at Microsoft who's familiar with the internal workings of
ToUnicodeEx()
.We need this function (or something similar) to translate Alt+Key combinations to proper unicode.
But at the same time it should not send us any additional IBM-style Alt Codes to our character handler if that translation fails (and
ToUnicodeEx()
returns 0).Validation Steps Performed
See #3101 for more information. I ensured that Alt+Arrow-Key combinations do not print ◘☻♠♦ anymore.