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

Autohotkey AltGr+7, AltGr+8, AltGr+9, and AltGr+0 reassignments lost in Windows Terminal Preview and Windows Terminal #7064

Closed
svivar opened this issue Jul 24, 2020 · 5 comments · Fixed by #7145
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@svivar
Copy link

svivar commented Jul 24, 2020

Environment

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd]
Windows Terminal version (if applicable):

Any other software?

Microsoft Windows [Version 10.0.19042.388]

Steps to reproduce

Expected behavior

I use the Spanish (ES) keyboard configuration and I have an autohotkey script that reassigns AltGr+, (comma), AltGr+. (period), AltGr+7, AltGr+8, AltGr+9, and AltGr+0 to <, >, «, », ‹, and ›, respectively.

I installed Windows Terminal and these keys-to-output reassignments worked great in tabs running PowerShell, cmd, Debian, and Ubuntu.

Actual behavior

I subsequently installed Windows Terminal Preview and found that AltGr+7, AltGr+8, AltGr+9, and AltGr+0 no longer produced any output. But the reassignment of outputs of AltGr+, (comma) and AltGr+. (period) to < and >, respectively, remain functional.

Windows Terminal also began exhibiting the same behavior.

The 6 autohotkey keys-to-output reassignments continue to work for all other applications.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jul 24, 2020
@zadjii-msft
Copy link
Member

You know what, I bet I busted this up when I was doing #4999. Summoning @lhecker for debugging advice ☺️

@zadjii-msft zadjii-msft added Area-Input Related to input processing (key presses, mouse, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. labels Jul 28, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Jul 28, 2020
@DHowett DHowett added this to the Terminal v2.0 milestone Jul 31, 2020
@DHowett DHowett added Help Wanted We encourage anyone to jump in on these. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jul 31, 2020
@lhecker
Copy link
Member

lhecker commented Aug 1, 2020

This can be tested by adding a keyboard layout that has an AltGr key (Spanish, German, French, ...) and running the following AutoHotKey script:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

<^>!,::SendInput {Raw}<
<^>!.::SendInput {Raw}>
<^>!7::SendInput {Raw<^>!8::SendInput {Raw<^>!9::SendInput {Raw}‹
<^>!0::SendInput {Raw}›

AFAICS the underlying issue is that #4999 breaks international character inputs, by handling all key events, thereby suppressing follow up character events. Key events are based on ASCII, making them fundamentally unsuitable to accurately recreate character inputs purely based on key event data. Our prior logic ignored all key events for which ToUnicodeEx returned a valid character and those who aren't in the special key-combination list in terminalInput.cpp.

AutoHotKey uses SendInput(). Using a German keyboard layout SendInput() first generates a Fn-key sequence (vkey = 255, scan_code = 0, ch = 0). WT (since #4999) acknowledges this sequence and thus prevents the unicode character (e.g. "»") from ever being sent to the character event handler.


For the time being I suggest non-US Terminal users to set "experimental.input.forceVT": true in their config.

@ghost ghost added the In-PR This issue has a related PR label Aug 1, 2020
@lhecker
Copy link
Member

lhecker commented Aug 1, 2020

I've opened a PR with an idea how I think this issue can be solved. 🙂 #7145

@svivar
Copy link
Author

svivar commented Aug 1, 2020

Thank you, @lhecker and @zadjii-msft . This comment may seem to be a digression to autohotkey, but I am posting it in case it's relevant to testing the fix to microsoft terminal preview. This is my autohotkey script:

<^>!,::Send <
<^>!.::Send >
<^>!7::Send {U+00AB}
<^>!8::Send {U+00BB}
<^>!9::Send {U+2039}
<^>!0::Send {U+203A}

Pressing those key sequences produces <>«»‹› in Notepad.

When I run the autohotkey script from @lhecker, these are what appear in Notepad: <>«»‹›

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
<^>!,::SendInput {Raw}<
<^>!.::SendInput {Raw}>
<^>!7::SendInput {Raw}«
<^>!8::SendInput {Raw}»
<^>!9::SendInput {Raw}‹
<^>!0::SendInput {Raw}›

I am currently running AutoHotkey 1.1.33.02.

@ghost ghost closed this as completed in #7145 Aug 6, 2020
@ghost ghost removed the In-PR This issue has a related PR label Aug 6, 2020
ghost pushed a commit that referenced this issue Aug 6, 2020
Up until #4999 we deferred all key events to the character event handler
for which `ToUnicodeEx` returned a valid character and alternatively
those who aren't a special key combination as listed in
`TerminalInput`'s implementation.

Since #4999 we started acknowledging/handling all key events no matter
whether they're actually a known key combination. Given non-ASCII inputs
the Win32 `SendInput()` method generates certain sequences that aren't
recognizable combinations though and if they're handled by the key event
handler no follow up character event is sent containing the unicode
character.

This PR adds another condition and defers all key events without scan
code (i.e. those not representable by the current keyboard layout) to
the character event handler.

I'm absolutely not certain that this PR doesn't have a negative effect
on other kinds of inputs.

Is it common for key events to not contain a scan code? I personally
haven't seen it happen before AutoHotKey/SendInput.

Before this PR is merged it'd be nice to have a good testing plan in
place in order to ensure nothing breaks.

## Validation Steps Performed

Remapped `AltGr+8` to `»` using AutoHotKey using `<^>!8::SendInput {Raw}»`.
Ensured `»` is printed if `AltGr+8` is pressed.

Closes #7064
Closes #7120
@ghost ghost added the Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. label Aug 6, 2020
DHowett pushed a commit that referenced this issue Aug 11, 2020
Up until #4999 we deferred all key events to the character event handler
for which `ToUnicodeEx` returned a valid character and alternatively
those who aren't a special key combination as listed in
`TerminalInput`'s implementation.

Since #4999 we started acknowledging/handling all key events no matter
whether they're actually a known key combination. Given non-ASCII inputs
the Win32 `SendInput()` method generates certain sequences that aren't
recognizable combinations though and if they're handled by the key event
handler no follow up character event is sent containing the unicode
character.

This PR adds another condition and defers all key events without scan
code (i.e. those not representable by the current keyboard layout) to
the character event handler.

I'm absolutely not certain that this PR doesn't have a negative effect
on other kinds of inputs.

Is it common for key events to not contain a scan code? I personally
haven't seen it happen before AutoHotKey/SendInput.

Before this PR is merged it'd be nice to have a good testing plan in
place in order to ensure nothing breaks.

## Validation Steps Performed

Remapped `AltGr+8` to `»` using AutoHotKey using `<^>!8::SendInput {Raw}»`.
Ensured `»` is printed if `AltGr+8` is pressed.

Closes #7064
Closes #7120

(cherry picked from commit b617c43)
@ghost
Copy link

ghost commented Aug 13, 2020

🎉This issue was addressed in #7145, which has now been successfully released as Windows Terminal Preview v1.2.2234.0.:tada:

Handy links:

zadjii-msft pushed a commit that referenced this issue Aug 8, 2023
…virtual keycode and a scan code of 0 (#15753)

## Summary
Applications like PowerToys, with their keyboard remapping features
frequently (i.e whenever a remapped shortcut is triggerred) send
`KeyEvent` with out-of-range virtual keycode values (E.g. 0xFF). This is
fixed for WT in #7145, we just needed it in our good ol' `conhost`.

After this PR, Key events with an invalid virtual keycode and
scancode==0 are ignored, and are not added to the `InputBuffer`. Incase,
only virtual keycode is valid but not scancode, we will try to infer the
correct scancode using the virtual keycode mapping.

## References and Relevant Issues
#7145 
#7064 

## Validation Steps Performed

- Triggered a remapped shortcut and verified that `showkey -a` doesn't
output `^@` unexpectedly.
- Key events with an Invalid virtual Keycode and Scancode == 0 are
ignored.
- This PR doesn't include any changes for `WM_[SYS][DEAD]CHAR` messages,
they are left unchanged.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants