mintty / wsltty

Mintty as a terminal for Bash on Ubuntu on Windows / WSL
Other
3.11k stars 104 forks source link

AltGr randomly stops working #337

Closed diddi- closed 11 months ago

diddi- commented 1 year ago

I'm shooting in the dark here but I've no idea where else to turn at the moment.

I'm using wsltty extensively on a daily basis with an Ubuntu WSL 1 instance. Works great except that every so often the AltGr just stops working. With a Swedish keyboard layout that means I can't type characters like @, |, [], {} etc. It's as if the AltGr key isn't recognized. The only way I found to get it back is to close the terminal and open a new one. It happens several times a day so it's quite often, I just haven't found a way to reliably reproduce it.

When it happens, it happens only in that specific terminal. Other terminals and apps/windows are not affected, although other terminals can/will later be affected too it's just they don't seem to be related to each other. With the "Ctrl+LeftAlt is AltGr" option enabled, I can still use that key combination to emulate AltGr. It's only the actual AltGr button that stops working.

I can't pinpoint what is triggering this and since there are potentially so many moving pieces involved I don't really know where to start.

If it helps, here is two outputs from showkeys on Ubuntu 20.04 WSL 1, bash 5.0.17(1)-release. The first one is from a working terminal, the second is from a terminal where AltGr is not working. The input from my keyboard is exactly the same in both cases. '|' (0x7c) isn't recognized at all in the second and '$' (0x24) becomes something else entirely.

Working:

$ showkey -a

Press any keys - Ctrl-D will terminate this program

w       119 0167 0x77
s       115 0163 0x73
l       108 0154 0x6c
t       116 0164 0x74
t       116 0164 0x74
y       121 0171 0x79
@        64 0100 0x40
g       103 0147 0x67
i       105 0151 0x69
t       116 0164 0x74
h       104 0150 0x68
u       117 0165 0x75
b        98 0142 0x62
|       124 0174 0x7c
$        36 0044 0x24
^D        4 0004 0x04

Broken AltGr

$ showkey -a

Press any keys - Ctrl-D will terminate this program

w       119 0167 0x77
s       115 0163 0x73
l       108 0154 0x6c
t       116 0164 0x74
t       116 0164 0x74
y       121 0171 0x79
^@        0 0000 0x00
g       103 0147 0x67
i       105 0151 0x69
t       116 0164 0x74
h       104 0150 0x68
u       117 0165 0x75
b        98 0142 0x62
^[[1;7s          27 0033 0x1b
         91 0133 0x5b
         49 0061 0x31
         59 0073 0x3b
         55 0067 0x37
        115 0163 0x73
^D        4 0004 0x04

I'm running mintty 3.6.4, wsltty 3.6.4 on Windows 10 (19045).

diddi- commented 1 year ago

Hmm, now that I look closer at the showkeys output I realize that it's like if CTRL being stuck in that terminal. Although it only affects using AltGr. All other keys work normally. No matter what I try I can't release it, and I still don't know what's triggering it. Might help narrow the troubleshooting down a bit though.

mintty commented 1 year ago

This sounds like you've accidentally switched the keyboard layout for the window, maybe with a hotkey (like Ctrl+Shift). Please check whether that's possible. I'm using German layout myself (also for @ | ä etc) and have never had such problems except while I had additional keyboard layouts installed for some testing.

diddi- commented 1 year ago

I don't think that's it. I only have one layout installed and the option to have different layouts per window is disabled.

mintty commented 1 year ago

it's like if CTRL being stuck

Another idea: If it happens, please try to hit Ctrl (maybe both Ctrl keys) and release them. Does AltGr work again? Do you often switch windows before this happens? It might be a Ctrl state glitch, maybe even a keyboard hardware issue.

puellanivis commented 1 year ago

Yeah, if Ctrl gets stuck, then AltGr won’t work. Unfortunately, (as I am sure many already know) in Windows AltGr is in-the-system identical to Ctrl+Alt, and there is now way to “fix” it.

Do Ctrl-Key inputs still work when AltGr stops working? 🤔 Very odd, and it would be great if the inbuilt AltGr wasn’t hacked in Windows how it is.

mintty commented 1 year ago

Windows AltGr is in-the-system identical to Ctrl+Alt

Actually this is almost true but not completely. Windows sends the two keycodes with identical timestamp by which AltGr can be distinguished. There are other keyboard drivers that do not reflect this properly like Teamviewer and even Windows' own onscreen keyboard but then timestamps are either very close, or you can check the scancode which is zero etc. There are a few tricky workarounds in mintty that try to compensate for such quirks.

diddi- commented 1 year ago

Thanks for the ideas

Another idea: If it happens, please try to hit Ctrl (maybe both Ctrl keys) and release them. Does AltGr work again? Do you often switch windows before this happens? It might be a Ctrl state glitch, maybe even a keyboard hardware issue.

I've tried hitting (both) Ctrl again and again, it doesn't seem to make a difference. I don't think it's stuck on an OS level as it appears fine in all other windows. I'm not even sure Ctrl is being stuck at all, might just be the same symptom/appearance of it. I do switch windows often sure but hard to say if it's close to when the issues start. I'll try and be more aware of it next time. I'm on a laptop with external keyboard. When the issue appears it's the same on both laptop and external keyboard so I don't think it's a hardware thing.

Do Ctrl-Key inputs still work when AltGr stops working?

They do. And not only that, I must hold Ctrl key for those inputs to work (for example Ctrl+R for reverse-search). This is one reason I think it's not actually stuck but just give a similar appearance of it.

mintty commented 1 year ago

Released 3.6.5. There are now two options that might help debug the issue:

StatusDebug=3
StatusLine=1

Please look out for the info insde [] in the bottom status line.

diddi- commented 1 year ago

Thanks! Will give this a try the coming week.

diddi- commented 1 year ago

Not sure what the info means but hopefully it makes more sense to you :)

From a working/functional terminal

user@host:~$
Status bar: [41D.000000]

user@host:~$ @£$€
Status bar: [41D.240002]

Non working terminal

user@host:~$ 
Status bar: [41D.000000]

user@host:~$ stu
Status bar: [41D.240006]

I used the exact same key sequence in both examples (AltGr + 1, 2, 3, 4, 5) but they gave very different results and the status bar is different too. I can't copy the entire bar if you need more info just let me know.

mintty commented 1 year ago

The info means you run a Swedish keyboard layout and press AltGr in the first case but Control+AltGr in the second case.

mintty commented 1 year ago

Non working terminal

You mean a terminal where it used to work and then stops working (as described before), right? Do you have a physical keyboard (USB or laptop built-in) or some kind of virtual keyboard / remote desktop?

diddi- commented 1 year ago

Non working terminal

You mean a terminal where it used to work and then stops working (as described before), right?

Correct.

Do you have a physical keyboard (USB or laptop built-in) or some kind of virtual keyboard / remote desktop?

I'm on laptop with both built-in and external USB keyboard. When the issue appears it's the same for both keyboards. I'm not on/using RDP, Temviewer or similar (I've seen a lot on google about these). Not sure if it narrows things down but I did notice yesterday it happened quite early in my wsltty session. All I managed to do was a quick ssh to a machine and exit right away, then a "docker compose up" and the issue was there. I can't tell if either of these are the culprit however.

mintty commented 1 year ago

it's like if CTRL being stuck

Just to get sure about a potential hardware problem, please make sure about two test cases:

diddi- commented 1 year ago

it's like if CTRL being stuck

Just to get sure about a potential hardware problem, please make sure about two test cases:

  • Use built-in keyboard only (USB unplugged)
  • Use external keyboard only for another terminal session

I just discovered I can reproduce the issue at will:

This works for all subsequent terminals. The latest opened will be working, all previous have the AltGr broken. I did try with different external keyboards and even unplugged with only built-in, makes no difference.

Another thing I noticed is that if I press AltGr many times (or hold it down) in a "broken" terminal, it will flip between [41D.240002] and [41D.240006] with maybe one [41D.240002] for every 10-20 keypresses, the rest is [41D.240006].

I'm wondering if there's something with my WSL environment causing this. No clue what that would be though...

mintty commented 1 year ago

For the sake of completeness:

Open up a terminal

means start a terminal with one of the wsltty desktop or Start menu shortcuts like "Debian Terminal" or "WSL Terminal"?

one [41D.240002] for every 10-20 keypresses

and this one works again?

And, even if it's intended for a more specific situation, please try also setting CtrlAltDelayAltGr=20

diddi- commented 1 year ago

For the sake of completeness:

Open up a terminal

means start a terminal with one of the wsltty desktop or Start menu shortcuts like "Debian Terminal" or "WSL Terminal"?

Yes. I have a wsltty shortcut pinned to the taskbar, opening a new means opening a new window from that shortcut.

one [41D.240002] for every 10-20 keypresses

and this one works again?

Not sure what you mean but If I spam the AltGr button enough times I can see it work once every so and so keypress and then it immediately reverts back to broken. It never fully recover.

And, even if it's intended for a more specific situation, please try also setting CtrlAltDelayAltGr=20

Tried this and it does not seem to make a difference unfortunately.

diddi- commented 11 months ago

I completely uninstalled and re-installed wsltty a few weeks ago (for different reasons) and now I don't have this problem anymore. I suspect something was just off with the previous install.