Occasionally, when pressing an arrow key (usually up) inside of a shell, the terminal or shell fails to output an ESC character before the escape sequence, so if I press the up arrow to try and see the last command, it outputs [A on bash and OA on zsh, instead of the last command. It works correctly the next time I press the arrow key.

This happens regardless of the terminal emulator or shell used (but it does use OA instead of [A when using zsh).

I can't tell the exact circumstances this occurs in, it seems somewhat random, but it usually happens the next time I press an arrow after switching windows with my window manager (i3).

It's not because I pressed the key too fast after switching windows, because I can switch windows, type text into the shell, and after that press an arrow key and it will still output [A/OA.

It might be related to the fact that I'm using i3 as my window manager.

Is there anything I can do to fix or debug this issue?

  • I assume you pressed the ESC key before this issue occurs. It's not that the opening ESC of the sequence is swallowed; it is instead combined with the previously buffered one (the two ESC bytes form something), and then subsequent OA or [A are treated as simple string literals. – egmont Nov 4 '17 at 9:05
  • If I press an ESC key before the issue, it's in another terminal. Pressing the ESC key in another terminal (usually inside vim) then switching terminals sometimes causes the problem, but it's not consistently reproducible. – Accumulator Nov 4 '17 at 18:56
  • How do you switch windows? Is a keystroke like Alt+Tab involved? What is it exactly? Try to test and report if there's a correlation: switch from the terminal to another window, then switch back, then press an arrow. Try all the combinations (0. keystroke forth, keystroke back; 1. keystroke forth, mouse click back; 2. click forth, keystroke back; 3. click forth, click back). – Kamil Maciorowski Nov 7 '17 at 2:08
  • I always switch windows with alt+hjkl (alt is the mod key) – Accumulator Nov 7 '17 at 2:10

I have not enough reputation to post comments, so please, dont downvote me, move my reply to comments instead if you feel like it is very dumb:

I see four possible scenarios (very general due to the lack of detail on driver, kernel, distribution, keyboard model...):

  1. Broken keyboard.
  2. Window manager problem.
  3. Driver/kernel problem.
  4. Locales problem.

Possible solutions:

  1. I've seen broken keyboards acting in a similar way, sending strange key signals at random times, specially (but not only) after pressing other specific keys (you said you switch windows using your keyboard aswell). Try another keyboard to see if it still happens. I've seen this more frecuently on wireless keyboards, but I've had my share of odd things on wired keyboards aswell. Check if it happens sometimes without the window manager opened, in console mode.
  2. There may be something wrong with i3 (without more details I cannot give you a deeper answer). Update i3, or temporary install another window manager and see if the error reproduces again.
  3. If you switch windows with the keyboard there may be something to do with the keyboard buffers not reading it correctly. Try updating the kernel to see if it solves que problem. If you have virtualization software installed maybe it broke your driver when insalling the keyboard hooks...
  4. There may be something odd in your keyboard locales. Even though this is very unlikely, you could try to fetch or generate a new locales file.
  • 1. It still happens, definitely not the keyboard. 2. Using bspwm now, no difference. 3. I will try that soon. 4. Trying it now. – Accumulator Nov 10 '17 at 21:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.