summaryrefslogtreecommitdiffstats
path: root/src/include/ipxe/keys.h
blob: b2a62744edaff893c119b1a70ecda12e16ab4988 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef _IPXE_KEYS_H
#define _IPXE_KEYS_H

/** @file
 *
 * Key definitions
 *
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
FILE_SECBOOT ( PERMITTED );

/*
 * Symbolic names for some standard ASCII characters
 *
 */

#define NUL		0x00
#define CTRL_A		0x01
#define CTRL_B		0x02
#define CTRL_C		0x03
#define CTRL_D		0x04
#define CTRL_E		0x05
#define CTRL_F		0x06
#define CTRL_G		0x07
#define CTRL_H		0x08
#define CTRL_I		0x09
#define CTRL_J		0x0a
#define CTRL_K		0x0b
#define CTRL_L		0x0c
#define CTRL_M		0x0d
#define CTRL_N		0x0e
#define CTRL_O		0x0f
#define CTRL_P		0x10
#define CTRL_Q		0x11
#define CTRL_R		0x12
#define CTRL_S		0x13
#define CTRL_T		0x14
#define CTRL_U		0x15
#define CTRL_V		0x16
#define CTRL_W		0x17
#define CTRL_X		0x18
#define CTRL_Y		0x19
#define CTRL_Z		0x1a

#define BACKSPACE	CTRL_H
#define TAB		CTRL_I
#define LF		CTRL_J
#define CR		CTRL_M
#define ESC		0x1b
#define DEL		0x7f

/*
 * Special keys outside the normal Unicode range
 *
 * The names are chosen to match those used by curses.  The values are
 * chosen to facilitate easy conversion from a received ANSI escape
 * sequence to a KEY_XXX constant.
 *
 * Note that the values are exposed to iPXE commands via parse_key()
 * and therefore may not be changed without breaking existing scripts.
 */

/**
 * Minimum value for special keypresses
 *
 * This value is chosen to lie above the maximum Unicode code point
 * value 0x10ffff.
 */
#define KEY_MIN		0x110000

/**
 * Construct relative key value for special key
 *
 * @v key		Key value
 * @ret rkey		Relative key value
 */
#define KEY_REL( key ) ( (key) - KEY_MIN )

/**
 * Construct ANSI escape sequence key value
 *
 * @v n			ANSI escape sequence numeric portion, or 0 for none
 * @v terminator	ANSI escape sequence terminating character
 * @ret key		Key value
 */
#define KEY_ANSI( n, terminator ) \
	( KEY_MIN + ( ( (n) + 1 ) << 8 ) + (terminator) )

/**
 * Extract ANSI escape sequence numeric portion
 *
 * @v key		Key value (or relative key value)
 * @ret n		ANSI escape sequence numeric portion, or 0 for none
 */
#define KEY_ANSI_N( key ) ( ( ( (key) >> 8 ) & 0xff ) - 1 )

/**
 * Extract ANSI escape sequence terminating character
 *
 * @v key		Key value (or relative key value)
 * @ret terminator	ANSI escape sequence terminating character
 */
#define KEY_ANSI_TERMINATOR( key ) ( (key) & 0xff )

#define KEY_UP		KEY_ANSI ( 0, 'A' )	/**< Up arrow */
#define KEY_DOWN	KEY_ANSI ( 0, 'B' )	/**< Down arrow */
#define KEY_RIGHT	KEY_ANSI ( 0, 'C' )	/**< Right arrow */
#define KEY_LEFT	KEY_ANSI ( 0, 'D' )	/**< Left arrow */
#define KEY_END		KEY_ANSI ( 0, 'F' )	/**< End */
#define KEY_HOME	KEY_ANSI ( 0, 'H' )	/**< Home */
#define KEY_IC		KEY_ANSI ( 2, '~' )	/**< Insert */
#define KEY_DC		KEY_ANSI ( 3, '~' )	/**< Delete */
#define KEY_PPAGE	KEY_ANSI ( 5, '~' )	/**< Page up */
#define KEY_NPAGE	KEY_ANSI ( 6, '~' )	/**< Page down */
#define KEY_F5		KEY_ANSI ( 15, '~' )	/**< F5 */
#define KEY_F6		KEY_ANSI ( 17, '~' )	/**< F6 */
#define KEY_F7		KEY_ANSI ( 18, '~' )	/**< F7 */
#define KEY_F8		KEY_ANSI ( 19, '~' )	/**< F8 (for PXE) */
#define KEY_F9		KEY_ANSI ( 20, '~' )	/**< F9 */
#define KEY_F10		KEY_ANSI ( 21, '~' )	/**< F10 */
#define KEY_F11		KEY_ANSI ( 23, '~' )	/**< F11 */
#define KEY_F12		KEY_ANSI ( 24, '~' )	/**< F12 */

/* Not in the [KEY_MIN,KEY_MAX] range; terminals seem to send these as
 * normal ASCII values.
 */
#define KEY_BACKSPACE	BACKSPACE
#define KEY_ENTER	LF

#endif /* _IPXE_KEYS_H */