(The theory is in the following 3 paragraphs and the best guess answer is developed in the remainder of this long winded explanation. The spoiler is our educated guess of 0x89
as the answer to the given question. If not then you'll probably need to read much of the rest and do some searching on your own to see exactly what you should send and how. I do hope this helps.)
To sort this out the first thing is to realize that C-M-i
is not the same as Control + Command + I
except when (in a specific context such as an OS or a program) the Command
key is set to be the Meta
key. In iTerm the choices for the Meta
key are one or the other of the Option (Alt) keys. In iTerm one can't speak of the Command key as the Meta key although it's possible to capture the Command key press by defining it as an iTerm
keyboard shortcut. So what does it mean in iTerm to press Control + Command + i
? It's not defined; it sends no visible or invisible characters at all. (This is best seen by invoking cat -v
, vis -o
or another program that will visibly display invisible codes and trying various keystrokes.)\
But the idea of pressing C-M-i
is somewhat defined and often including the Meta
key with another key combination is equivalent to pressing the ESCape
key followed by the same key combination. That appears to be what you were trying to do by setting a key to output the escape sequence: ESC + ^i
. If that didn't work then we need to know what string of characters/bytes is actually wanted by whatever program you are trying to control. Following the example you pointed to I created a hex sequence of 0x1B 0x09
which produced the same output as your ESC sequence. (Hex 1B
or 0x1B
= Binary 000110111
= Octal 033
or \033 = Decimal 27
…value of 27
not 2
followed by 7
; after a while these particular numbers all start to mean ESCape
character when one sees them.)
Now, Key Codes
was a good try being the same sort of idea as using cat
or vis
to visualize the characters that get sent. The problem is that Key Codes
is not running within iTerm
but is running within OS X.
One could say the Command
key is OS X's
Meta
key but that train of thought isn't useful since OS X
defines the function of its Meta
key quite differently from how iTerm
defines its Meta
key. If you go into Key Codes
and try pressing Control + i
with and without the Command
key you'll see that the difference is in the resulting modifiers; but the modifiers are internal flags within OS X
that OS X
creates by examining what keys are pressed. The actual output code is closest to the Unicode character shown (0x09
) and you'll see that both with and without the Command
key you receive the same character. But that's illusory anyway since what actually happens is that OS X
gets the Key Code and the Modifers values and interprets those codes as it wants. Control + i
comes closest to "sending" a ^i
but add the Command
key and, if the Finder
is the receiving the results, you get one of the various Get Info
commands; another program may interpret it as it likes. It's turtles on turtles on turtles all the way down, i.e., what you begin with may end up doing many different things depending on what is re-interpreting what, and so on.
Now I have to try to give you an answer that will work for you, but the preceding was necessary to show why I can't say for sure. But I can make an educated guess. First, the context is iTerm
and I assume you are running a program in iTerm that does something in response to what is said to be C-M-i.
If, in iTerm
I set one Option/Alt key to be the Meta key and then press that key with the ^i
keys we will expect that we will get what we want to happen to happen. So let's find out what gets sent by doing that. If you use Key Caps
it won't say anything different since you're back outside of iTerm.
But when I use the cat -v
command which does it's best to make the invisible visible on the screen and press C-M-i,
then along with a strange diamond shape character I get the string M-^i
which seems to be a way to say M-C-i
. That looks good.
Now I get out of the cat
program and go to the vis -o
program which will try to give me some octal values for some of the invisible characters. Now pressing C-M-i
gives me an octal value (after pressing return) of \211
as well as that funny diamond. (Octal 211
or \211
= Binary 10001001
= Hex 89
or 0x89;
which is encouraging since when I earlier turned on the Meta
key in iTerm
it gave me a warning a that Meta
was usually used on older systems and new systems generally use the +ESC
code sequence…back to where you started! I also have seen that what the Meta
key often did was to output the ASCII 7-bit printable character with its high-order bit (leftmost bit usually set to zero) set to 1. If you strip the leftmost 1 from the binary coding of what we received you're left with a 1001
binary = Decimal 9! 9
is the character that pressing ^i
"sends out." That looks good.
Just to go full circle and check it out further I can go back to iTerm,
make sure I've turned off my Meta
key options (just in case) and define a new keyboard shortcut to some key that sends a 0x89
(Hex 89
). Then open a new window so that the changes are active and press the key you assigned the 0x89
with vis -o
running to interpret your characters. Out comes the same funny diamond shape and the octal string \211
. So it appears we have set up a shortcut key to produce C-M-i
to the best of what we know.
Whether that key will do what you want depends on whether the program that wants that keyboard code handles what we gave it. Not knowing more this is a best educated guess. If it fails then it's necessary to delve further into the end program that is being controlled [I'd venture Emacs
but, hey, I use vi
so what do I know ;-] Hopefully some of the techniques and ideas presented here would help you determine how to send the correct codes once you found them. I hope that this works for you. Note that without all the fuss you can get a pretty good idea that it will or won't work by turning on a Meta
key in iTerm
and pressing C-M-i
to see if that works; if so then proceed to define your shortcut key.
Alt
– Amelio Vazquez-Reina Sep 08 '14 at 03:23