Alt arrow keys print extra characters #4323

Closed
opened 2026-01-30 23:44:05 +00:00 by claunia · 9 comments
Owner

Originally created by @paulwhiting on GitHub (Oct 7, 2019).

Terminal Version: 0.5.2762.0
Microsoft Windows [Version 10.0.18362.356]

Steps to reproduce

Open terminal. Press alt-up, alt-down, alt-right, alt-left.

(For byobu: start byobu with 'byobu'. Press F2 to add a new tab. Press alt-right and alt-left to switch between tabs.)

Expected behavior

Observed behavior

  • c:\windows\system32\bash.exe: ABCD is printed out as expected.
  • c:\windows\system32\bash.exe in byobu: Byobu tabs are switched on alt-left and alt-right. (Only a single session is running so alt-up and alt-down just error out as expected.) No additional characters are printed out, as expected.
  • Windows Powershell terminal (run->powershell): Nothing is printed out. (Expected? I don't know.)
  • Terminal App powershell: ☻♠♦ is printed out.
  • Terminal App ubuntu: A◘B☻C♠D♦ is printed out.
  • Terminal App ubuntu in byobu: Byobu tabs are are switched as expected, BUT when alt is released one of ◘☻♠♦ is printed out depending on which arrow key was pressed last.
Originally created by @paulwhiting on GitHub (Oct 7, 2019). Terminal Version: 0.5.2762.0 Microsoft Windows [Version 10.0.18362.356] ### Steps to reproduce Open terminal. Press alt-up, alt-down, alt-right, alt-left. (For byobu: start byobu with 'byobu'. Press F2 to add a new tab. Press alt-right and alt-left to switch between tabs.) ### Expected behavior - When not running something like byobu perhaps [the letters ABCD should be printed out](https://unix.stackexchange.com/questions/73669/what-are-the-characters-printed-when-altarrow-keys-are-pressed). - When using byobu to manage console sessions it should switch between tabs. ### Observed behavior - c:\windows\system32\bash.exe: ABCD is printed out as expected. - c:\windows\system32\bash.exe in byobu: Byobu tabs are switched on alt-left and alt-right. (Only a single session is running so alt-up and alt-down just error out as expected.) No additional characters are printed out, as expected. - Windows Powershell terminal (run->powershell): Nothing is printed out. (Expected? I don't know.) - Terminal App powershell: ☻♠♦ is printed out. - Terminal App ubuntu: A◘B☻C♠D♦ is printed out. - Terminal App ubuntu in byobu: Byobu tabs are are switched as expected, BUT when alt is released one of ◘☻♠♦ is printed out depending on which arrow key was pressed last.
Author
Owner

@rideron89 commented on GitHub (Oct 7, 2019):

I'm having the same issue. Happens in both fish and bash.

I use alt-left and alt-right to navigate through words on a command.

Terminal version: 0.5.2762.0
Windows 10 version 18362.388 (1903)

@rideron89 commented on GitHub (Oct 7, 2019): I'm having the same issue. Happens in both `fish` and `bash`. I use alt-left and alt-right to navigate through words on a command. Terminal version: 0.5.2762.0 Windows 10 version 18362.388 (1903)
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 7, 2019):

Confirmed! Possible regression from #2836 (/cc @lhecker)?

@DHowett-MSFT commented on GitHub (Oct 7, 2019): Confirmed! Possible regression from #2836 (/cc @lhecker)?
Author
Owner

@lhecker commented on GitHub (Oct 8, 2019):

@DHowett-MSFT This issue is caused by the use of ToUnicodeEx(), which has the following warning...

As ToUnicodeEx translates the virtual-key code, it also changes the state of the kernel-mode keyboard buffer. This state-change affects dead keys, ligatures, alt+numpad key entry, and so on. It might also cause undesired side-effects if used in conjunction with TranslateMessage (which also changes the state of the kernel-mode keyboard buffer).

I'll open a PR.

@paulwhiting I was not able to exactly replicate your observed behavior. Is there a way to switch between "keypad mode" on/off? I'm "Press[ing] alt-up, alt-down, alt-right, alt-left" (in that order) and I'm not really certain why I'm getting these different results:

  • C:\Windows\System32\bash.exe: Alt+Up/Down causes a beep (or "bing") and Alt+Left/Right jumps between words
  • Terminal App powershell: ◘☻♠♦ is printed out.
  • Terminal App ubuntu: ♦◘☻♠ is printed out.
@lhecker commented on GitHub (Oct 8, 2019): @DHowett-MSFT This issue is caused by the use of `ToUnicodeEx()`, which has the following warning... > As ToUnicodeEx translates the virtual-key code, it also changes the state of the kernel-mode keyboard buffer. This state-change affects dead keys, ligatures, alt+numpad key entry, and so on. It might also cause undesired side-effects if used in conjunction with TranslateMessage (which also changes the state of the kernel-mode keyboard buffer). I'll open a PR. @paulwhiting I was not able to exactly replicate your observed behavior. Is there a way to switch between "keypad mode" on/off? I'm "Press[ing] alt-up, alt-down, alt-right, alt-left" (in that order) and I'm not really certain why I'm getting these different results: * C:\Windows\System32\bash.exe: Alt+Up/Down causes a beep (or "bing") and Alt+Left/Right jumps between words * Terminal App powershell: ◘☻♠♦ is printed out. * Terminal App ubuntu: ♦◘☻♠ is printed out.
Author
Owner

@paulwhiting commented on GitHub (Oct 9, 2019):

I believe num lock should do what you want? My keyboard doesn't have a numeric keypad, just standalone arrow keys. You're not seeing the ABCD characters because your underlying shell is handling those. It's the extra one of ♦◘☻♠ that pops up after letting go of alt that's the problem.

@paulwhiting commented on GitHub (Oct 9, 2019): I believe num lock should do what you want? My keyboard doesn't have a numeric keypad, just standalone arrow keys. You're not seeing the ABCD characters because your underlying shell is handling those. It's the extra one of ♦◘☻♠ that pops up after letting go of alt that's the problem.
Author
Owner

@davy-tw commented on GitHub (Oct 15, 2019):

In my case, the extra keystroke will happens when I "release the Alt key" after pressing Alt+Left/Right/Up/Down.
If I don't release Alt key, the control key \cA \cB \cC \cD won't come out.

@davy-tw commented on GitHub (Oct 15, 2019): In my case, the extra keystroke will happens when I "release the Alt key" after pressing Alt+Left/Right/Up/Down. If I don't release Alt key, the control key `\cA` `\cB` `\cC` `\cD` won't come out.
Author
Owner

@sivaramn commented on GitHub (Oct 21, 2019):

can confirm, I too face this. Within tmux, if i switch panes using Alt+direction keys, i get funny chars on the command line

@sivaramn commented on GitHub (Oct 21, 2019): can confirm, I too face this. Within tmux, if i switch panes using Alt+direction keys, i get funny chars on the command line
Author
Owner

@daveshih01 commented on GitHub (Nov 13, 2019):

Hi folks, sorry for stating the obvious. Please review/approve the PR so this can be addressed. Thanks!

@daveshih01 commented on GitHub (Nov 13, 2019): Hi folks, sorry for stating the obvious. Please review/approve the [PR](https://github.com/microsoft/terminal/pull/3117) so this can be addressed. Thanks!
Author
Owner

@daveshih01 commented on GitHub (Nov 14, 2019):

Thanks, everyone!

@daveshih01 commented on GitHub (Nov 14, 2019): Thanks, everyone!
Author
Owner

@ghost commented on GitHub (Nov 26, 2019):

:tada:This issue was addressed in #3117, which has now been successfully released as Windows Terminal Preview v0.7.3291.0.🎉

Handy links:

@ghost commented on GitHub (Nov 26, 2019): :tada:This issue was addressed in #3117, which has now been successfully released as `Windows Terminal Preview v0.7.3291.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.7.3291.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4323