You can see the definition in the key_name(3)
manpage
Likewise, the meta
(3X) function allows the caller to change the output of keyname
, i.e., it determines whether to use the “M-” prefix for “meta” keys (codes in the range 128 to 255). Both use_legacy_coding
(3X) and meta
(3X) succeed only after curses is initialized. X/Open Curses does not document the treatment of codes 128 to 159. When treating them as “meta” keys (or if keyname
is called before initializing curses), this implementation returns strings “M-^@”
, “M-^A”
, etc.
key_name(3X)
So basically the Meta analog of the Ctrl version is the keycode of Ctrl + 128. You can see that easily in Brian's table. Here's a slightly modified version for ease of comparison
$ LC_ALL=C perl -e 'for( my $i=0 ; $i < 128; $i++ ) {
print ( sprintf( "%c is %d %x\t\t%c is %d %x\n",
$i, $i, $i, $i + 128, $i + 128, $i + 128 ) );
}' >bytes.txt
$ cat -v bytes.txt
^@ is 0 0 M-^@ is 128 80
^A is 1 1 M-^A is 129 81
^B is 2 2 M-^B is 130 82
^C is 3 3 M-^C is 131 83
...
^Y is 25 19 M-^Y is 153 99
^Z is 26 1a M-^Z is 154 9a
^[ is 27 1b M-^[ is 155 9b
^\ is 28 1c M-^\ is 156 9c
^] is 29 1d M-^] is 157 9d
^^ is 30 1e M-^^ is 158 9e
^_ is 31 1f M-^_ is 159 9f
is 32 20 M- is 160 a0
! is 33 21 M-! is 161 a1
" is 34 22 M-" is 162 a2
# is 35 23 M-# is 163 a3
$ is 36 24 M-$ is 164 a4
% is 37 25 M-% is 165 a5
& is 38 26 M-& is 166 a6
' is 39 27 M-' is 167 a7
( is 40 28 M-( is 168 a8
) is 41 29 M-) is 169 a9
* is 42 2a M-* is 170 aa
+ is 43 2b M-+ is 171 ab
, is 44 2c M-, is 172 ac
- is 45 2d M-- is 173 ad
. is 46 2e M-. is 174 ae
/ is 47 2f M-/ is 175 af
0 is 48 30 M-0 is 176 b0
1 is 49 31 M-1 is 177 b1
...
: is 58 3a M-: is 186 ba
; is 59 3b M-; is 187 bb
< is 60 3c M-< is 188 bc
= is 61 3d M-= is 189 bd
> is 62 3e M-> is 190 be
? is 63 3f M-? is 191 bf
@ is 64 40 M-@ is 192 c0
A is 65 41 M-A is 193 c1
B is 66 42 M-B is 194 c2
...
Z is 90 5a M-Z is 218 da
[ is 91 5b M-[ is 219 db
\ is 92 5c M-\ is 220 dc
] is 93 5d M-] is 221 dd
^ is 94 5e M-^ is 222 de
_ is 95 5f M-_ is 223 df
` is 96 60 M-` is 224 e0
a is 97 61 M-a is 225 e1
b is 98 62 M-b is 226 e2
...
z is 122 7a M-z is 250 fa
{ is 123 7b M-{ is 251 fb
| is 124 7c M-| is 252 fc
} is 125 7d M-} is 253 fd
~ is 126 7e M-~ is 254 fe
^? is 127 7f M-^? is 255 ff
The part after M-
on the right is exactly the same as on the left, with the keycodes differ by 128
You can also check cat's source code, the basic expression is *bpout++ = ch - 128;
for the Meta key version in the show_nonprinting
case