Hex codes for input key combinations

key mappingkeyboard shortcutsterminal

In iTerm2 one can setup keyboard shortcuts so that for a given input sequence, iTerm2 sends a specific hex code to the terminal.

What exactly are these hex codes? And how can I identify a hex code for a given input key sequence?

In my case I am specifically interested in looking up the hex code associated with Control + Alt + <char> with char being u,i,j,k and l.

I found this article that shows some examples of these conversions, but it doesn't list any Control + Alt + <char> combinations.

The hope is that ultimately this will help me solve this other question in AskDifferent.

Best Answer

It's not a matter of looking up those keycodes, because in its default configuration iTerm2 doesn't do anything special for the keys. For instance, if you do

cat -v

and press controlV ("literal next") before pressing each of those controlalt+character combinations, you're likely to find (as I did) that the result is just as if it ignored the alt modifier. The rather long answer in Sending Control+Alt+ <char> to terminal in iTerm2 seems to have concluded something based on this default behavior which is not helpful.

On the other hand, you can define a key binding, using hexadecimal values for the (ASCII) characters that you would like to send. In this screenshot, I have highlighted a binding that I added for controlaltf (lowercase F), which is 0x66:

example of send-hex-codes

The iIterm2 documentation is brief:

Send Hex Code

This action allows you to enter a sequence of hex codes that will be sent. Each value should begin with "0x" followed by one or two hex digits (0-9, a-f, or A-F). Each code should be separated by a space. You can see a list of hex codes on http://asciitable.com/ in the "Hx" column.

but the screenshot here may help you understand what's needed.

Related Question