Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Unix terminals send ASCII codes below 32 for Ctrl + another key, and have at least two ways of sending "meta" (viz. either prefixing code 27 or setting the high bit of an ASCII character). Is there a precedent for a way to encode the use of other modifier keys, like "super" or the Windows logo key or Mac Cmd key?

I'd like to map Cmd+arrow keys in iTerm2, but I don't know what codes to assign to them. I'm already using the Option key for "meta" with arrow keys.

share|improve this question
up vote 0 down vote accepted

The convention of setting the 8th bit when meta is pressed is rather archaic and isn't used much anymore, or indeed at all in any modern terminal that supports more characters than just ASCII. The convention of prefixing ESC is uncommon today too, for that matter.

The 32 ASCII control characters are indeed send as ASCII control characters (code points less than 32) but that only covers Ctrl-@, Ctrl-A through Ctrl-Z, ESC, Ctrl-\, Ctrl-], Ctrl-^, and Ctrl-_. Anything else, such as for exemple Ctrl-4, doesn't exist in ASCII and there is no convention for sending it through a terminal.

Basically, the bottom line is this: anything that can't be sent as a plain character (i.e. exists in Unicode for modern Unicode-supporting terminals) has to be sent as an escape sequence. Escape sequences are defined by the terminal emulation protocol in effect. Almost all terminal emulation protocols used today are derived from or similar to VT100, and escape sequences are available for common keys found on keyboards that don't exist as characters: arrow keys, function keys, etc...

VT100 and related terminal emulation protocols contain no conventions for conveying modifier keypresses, not even the standard ones like Shift and Control. Software running on a tty cannot tell the difference between an Enter keypress and a Shift-Enter keypress. It cannot even tell the difference between an Enter keypress and a Control-M keypress.

The fact that these modifier sequences can't be transmitted through a terminal can be considered a good thing. For example, the MacOS terminal application can claim the ⌘V keystroke for its own use (paste) because it can't be send to the tty anyway.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .