Search code examples
javascriptnode.jsmc

What code does Midnight Commander recognize for the cursor keys?


I have a web ssh terminal app using 'xterm.js' in the browser, and the 'ws' and 'ssh2' npm modules from node.js to connect to an ssh server. I've implemented a swipe gesture that sends the ansi codes esc+'[A', esc+'[B', esc+'[C', and esc+'[D', to simulate arrow keys for up, down, right, and left, where esc is the code for escape ("\033"). It works fine on the bash command line, but in Midnight Commander it just outputs the characters 'A', 'B', 'C', or 'D', without the left bracket (or apparently the escape).

Does MC use a different code? I know 'learn keys' is an option, but I need it to work out of the box on any ansi terminal.

Additional info:

Server is ubuntu lts linux. TERM is 'xterm-color'.

Hackers Keyboard arrow keys work for both. Arrow keys on physical keyboard work for both.

Typing arrow keys into 'sed -n l' gives me the above codes from any keyboard. Swipe gestures into 'sed -n l' show identical codes as 'real' cursor keys.

Using \x1b, \u001b, or \033 for escape all give same results.

Encoding is utf-8 across the board.


Solution

  • Ok. The answer is:

    esc+'OA', esc+'OB', esc+'OC', and esc+'OD'

    No bracket. Same code, just replace it with an uppercase O.

    Either seems to work in bash, but only the O version without the bracket worked in MC.