1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
10 * Keycode definitions for special keys.
12 * Any special key code sequences are replaced by these codes.
16 * For MSDOS some keys produce codes larger than 0xff. They are split into two
17 * chars, the first one is K_NUL (same value used in term.h).
19 #define K_NUL (0xce) /* for MSDOS: special key follows */
22 * K_SPECIAL is the first byte of a special key code and is always followed by
24 * The second byte can have any value. ASCII is used for normal termcap
25 * entries, 0x80 and higher for special keys, see below.
26 * The third byte is guaranteed to be between 0x02 and 0x7f.
29 #define K_SPECIAL (0x80)
32 * Positive characters are "normal" characters.
33 * Negative characters are special key codes. Only characters below -0x200
34 * are used to so that the absolute value can't be mistaken for a single-byte
37 #define IS_SPECIAL(c) ((c) < 0)
40 * Characters 0x0100 - 0x01ff have a special meaning for abbreviations.
41 * Multi-byte characters also have ABBR_OFF added, thus are above 0x0200.
43 #define ABBR_OFF 0x100
46 * NUL cannot be in the input string, therefore it is replaced by
47 * K_SPECIAL KS_ZERO KE_FILLER
52 * K_SPECIAL cannot be in the input string, therefore it is replaced by
53 * K_SPECIAL KS_SPECIAL KE_FILLER
55 #define KS_SPECIAL 254
58 * KS_EXTRA is used for keys that have no termcap name
59 * K_SPECIAL KS_EXTRA KE_xxx
64 * KS_MODIFIER is used when a modifier is given for a (special) key
65 * K_SPECIAL KS_MODIFIER bitmask
67 #define KS_MODIFIER 252
70 * These are used for the GUI
71 * K_SPECIAL KS_xxx KE_FILLER
75 #define KS_VER_SCROLLBAR 249
76 #define KS_HOR_SCROLLBAR 248
79 * These are used for DEC mouse
81 #define KS_NETTERM_MOUSE 247
82 #define KS_DEC_MOUSE 246
85 * Used for switching Select mode back on after a mapping or menu.
88 #define K_SELECT_STRING (char_u *)"\200\365X"
91 * Used for tearing off a menu.
93 #define KS_TEAROFF 244
95 /* used for JSB term mouse */
96 #define KS_JSBTERM_MOUSE 243
98 /* used a termcap entry that produces a normal character */
101 /* Used for the qnx pterm mouse */
102 #define KS_PTERM_MOUSE 241
104 /* Used for click in a tab pages label. */
105 #define KS_TABLINE 240
107 /* Used for menu in a tab pages line. */
108 #define KS_TABMENU 239
111 * Filler used after KS_SPECIAL and others
113 #define KE_FILLER ('X')
116 * translation of three byte code "K_SPECIAL a b" into int "K_xxx" and back
118 #define TERMCAP2KEY(a, b) (-((a) + ((int)(b) << 8)))
119 #define KEY2TERMCAP0(x) ((-(x)) & 0xff)
120 #define KEY2TERMCAP1(x) (((unsigned)(-(x)) >> 8) & 0xff)
123 * get second or third byte when translating special key code into three bytes
125 #define K_SECOND(c) ((c) == K_SPECIAL ? KS_SPECIAL : (c) == NUL ? KS_ZERO : KEY2TERMCAP0(c))
127 #define K_THIRD(c) (((c) == K_SPECIAL || (c) == NUL) ? KE_FILLER : KEY2TERMCAP1(c))
130 * get single int code from second byte after K_SPECIAL
132 #define TO_SPECIAL(a, b) ((a) == KS_SPECIAL ? K_SPECIAL : (a) == KS_ZERO ? K_ZERO : TERMCAP2KEY(a, b))
135 * Codes for keys that do not have a termcap name.
137 * K_SPECIAL KS_EXTRA KE_xxx
141 KE_NAME
= 3 /* name of this terminal entry */
143 , KE_S_UP
/* shift-up */
144 , KE_S_DOWN
/* shift-down */
146 , KE_S_F1
/* shifted function keys */
187 , KE_MOUSE
/* mouse event start */
190 * Symbols for pseudo keys which are translated from the real key symbols
193 , KE_LEFTMOUSE
/* Left mouse button click */
194 , KE_LEFTDRAG
/* Drag with left mouse button down */
195 , KE_LEFTRELEASE
/* Left mouse button release */
196 , KE_MIDDLEMOUSE
/* Middle mouse button click */
197 , KE_MIDDLEDRAG
/* Drag with middle mouse button down */
198 , KE_MIDDLERELEASE
/* Middle mouse button release */
199 , KE_RIGHTMOUSE
/* Right mouse button click */
200 , KE_RIGHTDRAG
/* Drag with right mouse button down */
201 , KE_RIGHTRELEASE
/* Right mouse button release */
203 , KE_IGNORE
/* Ignored mouse drag/release */
205 , KE_TAB
/* unshifted TAB key */
206 , KE_S_TAB_OLD
/* shifted TAB key (no longer used) */
208 , KE_SNIFF
/* SNiFF+ input waiting */
210 , KE_XF1
/* extra vt100 function keys for xterm */
214 , KE_XEND
/* extra (vt100) end key for xterm */
215 , KE_ZEND
/* extra (vt100) end key for xterm */
216 , KE_XHOME
/* extra (vt100) home key for xterm */
217 , KE_ZHOME
/* extra (vt100) home key for xterm */
218 , KE_XUP
/* extra vt100 cursor keys for xterm */
223 , KE_LEFTMOUSE_NM
/* non-mappable Left mouse button click */
224 , KE_LEFTRELEASE_NM
/* non-mappable left mouse button release */
226 , KE_S_XF1
/* extra vt100 shifted function keys for xterm */
231 , KE_MOUSEDOWN
/* scroll wheel pseudo-button Down */
232 , KE_MOUSEUP
/* scroll wheel pseudo-button Up */
234 , KE_KINS
/* keypad Insert key */
235 , KE_KDEL
/* keypad Delete key */
237 , KE_CSI
/* CSI typed directly */
239 , KE_PLUG
/* <Plug> */
240 , KE_CMDWIN
/* open command-line window from Command-line Mode */
242 , KE_C_LEFT
/* control-left */
243 , KE_C_RIGHT
/* control-right */
244 , KE_C_HOME
/* control-home */
245 , KE_C_END
/* control-end */
247 , KE_X1MOUSE
/* X1/X2 mouse-buttons */
254 , KE_DROP
/* DnD data is available */
255 , KE_CURSORHOLD
/* CursorHold event */
256 , KE_NOP
/* doesn't do something */
260 * the three byte codes are replaced with the following int when using vgetc()
262 #define K_ZERO TERMCAP2KEY(KS_ZERO, KE_FILLER)
264 #define K_UP TERMCAP2KEY('k', 'u')
265 #define K_DOWN TERMCAP2KEY('k', 'd')
266 #define K_LEFT TERMCAP2KEY('k', 'l')
267 #define K_RIGHT TERMCAP2KEY('k', 'r')
268 #define K_S_UP TERMCAP2KEY(KS_EXTRA, KE_S_UP)
269 #define K_S_DOWN TERMCAP2KEY(KS_EXTRA, KE_S_DOWN)
270 #define K_S_LEFT TERMCAP2KEY('#', '4')
271 #define K_C_LEFT TERMCAP2KEY(KS_EXTRA, KE_C_LEFT)
272 #define K_S_RIGHT TERMCAP2KEY('%', 'i')
273 #define K_C_RIGHT TERMCAP2KEY(KS_EXTRA, KE_C_RIGHT)
274 #define K_S_HOME TERMCAP2KEY('#', '2')
275 #define K_C_HOME TERMCAP2KEY(KS_EXTRA, KE_C_HOME)
276 #define K_S_END TERMCAP2KEY('*', '7')
277 #define K_C_END TERMCAP2KEY(KS_EXTRA, KE_C_END)
278 #define K_TAB TERMCAP2KEY(KS_EXTRA, KE_TAB)
279 #define K_S_TAB TERMCAP2KEY('k', 'B')
281 /* extra set of function keys F1-F4, for vt100 compatible xterm */
282 #define K_XF1 TERMCAP2KEY(KS_EXTRA, KE_XF1)
283 #define K_XF2 TERMCAP2KEY(KS_EXTRA, KE_XF2)
284 #define K_XF3 TERMCAP2KEY(KS_EXTRA, KE_XF3)
285 #define K_XF4 TERMCAP2KEY(KS_EXTRA, KE_XF4)
287 /* extra set of cursor keys for vt100 compatible xterm */
288 #define K_XUP TERMCAP2KEY(KS_EXTRA, KE_XUP)
289 #define K_XDOWN TERMCAP2KEY(KS_EXTRA, KE_XDOWN)
290 #define K_XLEFT TERMCAP2KEY(KS_EXTRA, KE_XLEFT)
291 #define K_XRIGHT TERMCAP2KEY(KS_EXTRA, KE_XRIGHT)
293 #define K_F1 TERMCAP2KEY('k', '1') /* function keys */
294 #define K_F2 TERMCAP2KEY('k', '2')
295 #define K_F3 TERMCAP2KEY('k', '3')
296 #define K_F4 TERMCAP2KEY('k', '4')
297 #define K_F5 TERMCAP2KEY('k', '5')
298 #define K_F6 TERMCAP2KEY('k', '6')
299 #define K_F7 TERMCAP2KEY('k', '7')
300 #define K_F8 TERMCAP2KEY('k', '8')
301 #define K_F9 TERMCAP2KEY('k', '9')
302 #define K_F10 TERMCAP2KEY('k', ';')
304 #define K_F11 TERMCAP2KEY('F', '1')
305 #define K_F12 TERMCAP2KEY('F', '2')
306 #define K_F13 TERMCAP2KEY('F', '3')
307 #define K_F14 TERMCAP2KEY('F', '4')
308 #define K_F15 TERMCAP2KEY('F', '5')
309 #define K_F16 TERMCAP2KEY('F', '6')
310 #define K_F17 TERMCAP2KEY('F', '7')
311 #define K_F18 TERMCAP2KEY('F', '8')
312 #define K_F19 TERMCAP2KEY('F', '9')
313 #define K_F20 TERMCAP2KEY('F', 'A')
315 #define K_F21 TERMCAP2KEY('F', 'B')
316 #define K_F22 TERMCAP2KEY('F', 'C')
317 #define K_F23 TERMCAP2KEY('F', 'D')
318 #define K_F24 TERMCAP2KEY('F', 'E')
319 #define K_F25 TERMCAP2KEY('F', 'F')
320 #define K_F26 TERMCAP2KEY('F', 'G')
321 #define K_F27 TERMCAP2KEY('F', 'H')
322 #define K_F28 TERMCAP2KEY('F', 'I')
323 #define K_F29 TERMCAP2KEY('F', 'J')
324 #define K_F30 TERMCAP2KEY('F', 'K')
326 #define K_F31 TERMCAP2KEY('F', 'L')
327 #define K_F32 TERMCAP2KEY('F', 'M')
328 #define K_F33 TERMCAP2KEY('F', 'N')
329 #define K_F34 TERMCAP2KEY('F', 'O')
330 #define K_F35 TERMCAP2KEY('F', 'P')
331 #define K_F36 TERMCAP2KEY('F', 'Q')
332 #define K_F37 TERMCAP2KEY('F', 'R')
334 /* extra set of shifted function keys F1-F4, for vt100 compatible xterm */
335 #define K_S_XF1 TERMCAP2KEY(KS_EXTRA, KE_S_XF1)
336 #define K_S_XF2 TERMCAP2KEY(KS_EXTRA, KE_S_XF2)
337 #define K_S_XF3 TERMCAP2KEY(KS_EXTRA, KE_S_XF3)
338 #define K_S_XF4 TERMCAP2KEY(KS_EXTRA, KE_S_XF4)
340 #define K_S_F1 TERMCAP2KEY(KS_EXTRA, KE_S_F1) /* shifted func. keys */
341 #define K_S_F2 TERMCAP2KEY(KS_EXTRA, KE_S_F2)
342 #define K_S_F3 TERMCAP2KEY(KS_EXTRA, KE_S_F3)
343 #define K_S_F4 TERMCAP2KEY(KS_EXTRA, KE_S_F4)
344 #define K_S_F5 TERMCAP2KEY(KS_EXTRA, KE_S_F5)
345 #define K_S_F6 TERMCAP2KEY(KS_EXTRA, KE_S_F6)
346 #define K_S_F7 TERMCAP2KEY(KS_EXTRA, KE_S_F7)
347 #define K_S_F8 TERMCAP2KEY(KS_EXTRA, KE_S_F8)
348 #define K_S_F9 TERMCAP2KEY(KS_EXTRA, KE_S_F9)
349 #define K_S_F10 TERMCAP2KEY(KS_EXTRA, KE_S_F10)
351 #define K_S_F11 TERMCAP2KEY(KS_EXTRA, KE_S_F11)
352 #define K_S_F12 TERMCAP2KEY(KS_EXTRA, KE_S_F12)
353 /* K_S_F13 to K_S_F37 are currently not used */
355 #define K_HELP TERMCAP2KEY('%', '1')
356 #define K_UNDO TERMCAP2KEY('&', '8')
358 #define K_BS TERMCAP2KEY('k', 'b')
360 #define K_INS TERMCAP2KEY('k', 'I')
361 #define K_KINS TERMCAP2KEY(KS_EXTRA, KE_KINS)
362 #define K_DEL TERMCAP2KEY('k', 'D')
363 #define K_KDEL TERMCAP2KEY(KS_EXTRA, KE_KDEL)
364 #define K_HOME TERMCAP2KEY('k', 'h')
365 #define K_KHOME TERMCAP2KEY('K', '1') /* keypad home (upper left) */
366 #define K_XHOME TERMCAP2KEY(KS_EXTRA, KE_XHOME)
367 #define K_ZHOME TERMCAP2KEY(KS_EXTRA, KE_ZHOME)
368 #define K_END TERMCAP2KEY('@', '7')
369 #define K_KEND TERMCAP2KEY('K', '4') /* keypad end (lower left) */
370 #define K_XEND TERMCAP2KEY(KS_EXTRA, KE_XEND)
371 #define K_ZEND TERMCAP2KEY(KS_EXTRA, KE_ZEND)
372 #define K_PAGEUP TERMCAP2KEY('k', 'P')
373 #define K_PAGEDOWN TERMCAP2KEY('k', 'N')
374 #define K_KPAGEUP TERMCAP2KEY('K', '3') /* keypad pageup (upper R.) */
375 #define K_KPAGEDOWN TERMCAP2KEY('K', '5') /* keypad pagedown (lower R.) */
377 #define K_KPLUS TERMCAP2KEY('K', '6') /* keypad plus */
378 #define K_KMINUS TERMCAP2KEY('K', '7') /* keypad minus */
379 #define K_KDIVIDE TERMCAP2KEY('K', '8') /* keypad / */
380 #define K_KMULTIPLY TERMCAP2KEY('K', '9') /* keypad * */
381 #define K_KENTER TERMCAP2KEY('K', 'A') /* keypad Enter */
382 #define K_KPOINT TERMCAP2KEY('K', 'B') /* keypad . or ,*/
384 #define K_K0 TERMCAP2KEY('K', 'C') /* keypad 0 */
385 #define K_K1 TERMCAP2KEY('K', 'D') /* keypad 1 */
386 #define K_K2 TERMCAP2KEY('K', 'E') /* keypad 2 */
387 #define K_K3 TERMCAP2KEY('K', 'F') /* keypad 3 */
388 #define K_K4 TERMCAP2KEY('K', 'G') /* keypad 4 */
389 #define K_K5 TERMCAP2KEY('K', 'H') /* keypad 5 */
390 #define K_K6 TERMCAP2KEY('K', 'I') /* keypad 6 */
391 #define K_K7 TERMCAP2KEY('K', 'J') /* keypad 7 */
392 #define K_K8 TERMCAP2KEY('K', 'K') /* keypad 8 */
393 #define K_K9 TERMCAP2KEY('K', 'L') /* keypad 9 */
395 #define K_MOUSE TERMCAP2KEY(KS_MOUSE, KE_FILLER)
396 #define K_MENU TERMCAP2KEY(KS_MENU, KE_FILLER)
397 #define K_VER_SCROLLBAR TERMCAP2KEY(KS_VER_SCROLLBAR, KE_FILLER)
398 #define K_HOR_SCROLLBAR TERMCAP2KEY(KS_HOR_SCROLLBAR, KE_FILLER)
400 #define K_NETTERM_MOUSE TERMCAP2KEY(KS_NETTERM_MOUSE, KE_FILLER)
401 #define K_DEC_MOUSE TERMCAP2KEY(KS_DEC_MOUSE, KE_FILLER)
402 #define K_JSBTERM_MOUSE TERMCAP2KEY(KS_JSBTERM_MOUSE, KE_FILLER)
403 #define K_PTERM_MOUSE TERMCAP2KEY(KS_PTERM_MOUSE, KE_FILLER)
405 #define K_SELECT TERMCAP2KEY(KS_SELECT, KE_FILLER)
406 #define K_TEAROFF TERMCAP2KEY(KS_TEAROFF, KE_FILLER)
408 #define K_TABLINE TERMCAP2KEY(KS_TABLINE, KE_FILLER)
409 #define K_TABMENU TERMCAP2KEY(KS_TABMENU, KE_FILLER)
412 * Symbols for pseudo keys which are translated from the real key symbols
415 #define K_LEFTMOUSE TERMCAP2KEY(KS_EXTRA, KE_LEFTMOUSE)
416 #define K_LEFTMOUSE_NM TERMCAP2KEY(KS_EXTRA, KE_LEFTMOUSE_NM)
417 #define K_LEFTDRAG TERMCAP2KEY(KS_EXTRA, KE_LEFTDRAG)
418 #define K_LEFTRELEASE TERMCAP2KEY(KS_EXTRA, KE_LEFTRELEASE)
419 #define K_LEFTRELEASE_NM TERMCAP2KEY(KS_EXTRA, KE_LEFTRELEASE_NM)
420 #define K_MIDDLEMOUSE TERMCAP2KEY(KS_EXTRA, KE_MIDDLEMOUSE)
421 #define K_MIDDLEDRAG TERMCAP2KEY(KS_EXTRA, KE_MIDDLEDRAG)
422 #define K_MIDDLERELEASE TERMCAP2KEY(KS_EXTRA, KE_MIDDLERELEASE)
423 #define K_RIGHTMOUSE TERMCAP2KEY(KS_EXTRA, KE_RIGHTMOUSE)
424 #define K_RIGHTDRAG TERMCAP2KEY(KS_EXTRA, KE_RIGHTDRAG)
425 #define K_RIGHTRELEASE TERMCAP2KEY(KS_EXTRA, KE_RIGHTRELEASE)
426 #define K_X1MOUSE TERMCAP2KEY(KS_EXTRA, KE_X1MOUSE)
427 #define K_X1MOUSE TERMCAP2KEY(KS_EXTRA, KE_X1MOUSE)
428 #define K_X1DRAG TERMCAP2KEY(KS_EXTRA, KE_X1DRAG)
429 #define K_X1RELEASE TERMCAP2KEY(KS_EXTRA, KE_X1RELEASE)
430 #define K_X2MOUSE TERMCAP2KEY(KS_EXTRA, KE_X2MOUSE)
431 #define K_X2DRAG TERMCAP2KEY(KS_EXTRA, KE_X2DRAG)
432 #define K_X2RELEASE TERMCAP2KEY(KS_EXTRA, KE_X2RELEASE)
434 #define K_IGNORE TERMCAP2KEY(KS_EXTRA, KE_IGNORE)
435 #define K_NOP TERMCAP2KEY(KS_EXTRA, KE_NOP)
437 #define K_SNIFF TERMCAP2KEY(KS_EXTRA, KE_SNIFF)
439 #define K_MOUSEDOWN TERMCAP2KEY(KS_EXTRA, KE_MOUSEDOWN)
440 #define K_MOUSEUP TERMCAP2KEY(KS_EXTRA, KE_MOUSEUP)
442 #define K_CSI TERMCAP2KEY(KS_EXTRA, KE_CSI)
443 #define K_SNR TERMCAP2KEY(KS_EXTRA, KE_SNR)
444 #define K_PLUG TERMCAP2KEY(KS_EXTRA, KE_PLUG)
445 #define K_CMDWIN TERMCAP2KEY(KS_EXTRA, KE_CMDWIN)
447 #define K_DROP TERMCAP2KEY(KS_EXTRA, KE_DROP)
449 #define K_CURSORHOLD TERMCAP2KEY(KS_EXTRA, KE_CURSORHOLD)
451 /* Bits for modifier mask */
452 /* 0x01 cannot be used, because the modifier must be 0x02 or higher */
453 #define MOD_MASK_SHIFT 0x02
454 #define MOD_MASK_CTRL 0x04
455 #define MOD_MASK_ALT 0x08 /* aka META */
456 #define MOD_MASK_META 0x10 /* META when it's different from ALT */
457 #define MOD_MASK_2CLICK 0x20 /* use MOD_MASK_MULTI_CLICK */
458 #define MOD_MASK_3CLICK 0x40 /* use MOD_MASK_MULTI_CLICK */
459 #define MOD_MASK_4CLICK 0x60 /* use MOD_MASK_MULTI_CLICK */
461 # define MOD_MASK_CMD 0x80
464 #define MOD_MASK_MULTI_CLICK (MOD_MASK_2CLICK|MOD_MASK_3CLICK|MOD_MASK_4CLICK)
467 * The length of the longest special key name, including modifiers.
468 * Current longest is <M-C-S-T-4-MiddleRelease> (length includes '<' and '>').
470 #define MAX_KEY_NAME_LEN 25
472 /* Maximum length of a special key event as tokens. This includes modifiers.
473 * The longest event is something like <M-C-S-T-4-LeftDrag> which would be the
474 * following string of tokens:
476 * <K_SPECIAL> <KS_MODIFIER> bitmask <K_SPECIAL> <KS_EXTRA> <KT_LEFTDRAG>.
478 * This is a total of 6 tokens, and is currently the longest one possible.
480 #define MAX_KEY_CODE_LEN 6