1 /**
2  * @namespace   biewlib
3  * @file        biewlib/sysdep/generic/unix/kbd_code.h
4  * @brief       This file contains definitions of keyboard codes
5  * @version     -
6  * @remark      this source file is part of Binary vIEW project (BIEW).
7  *              The Binary vIEW (BIEW) is copyright (C) 1995 Nickols_K.
8  *              All rights reserved. This software is redistributable under the
9  *              licence given in the file "Licence.en" ("Licence.ru" in russian
10  *              translation) distributed in the BIEW archive.
11  * @note        Requires POSIX compatible development system
12  *
13  * @author      Konstantin Boldyshev
14  * @since       1999
15  * @note        Development, fixes and improvements
16 **/
17 
18 /*
19     Copyright (C) 1999-2001 Konstantin Boldyshev <konst@linuxassembly.org>
20 
21     $Id: kbd_code.h,v 1.3 2009/09/03 16:57:40 nickols_k Exp $
22 */
23 
24 #ifndef __KBD_CODE_H
25 #define __KBD_CODE_H
26 
27 #define KS_SHIFT	3
28 #define KS_CTRL		4
29 #define KS_ALT		8
30 #define KS_CTRL_MASK	15
31 #define KS_SCRLOCK	16
32 #define KS_NUMLOCK	32
33 #define KS_CAPSLOCK	64
34 #define KS_INSERT	128
35 
36 /*
37     not real keys, for internal use only
38 */
39 
40 #define KE_SUPERKEY	0xFFFF
41 #define KE_JUSTFIND	0xFFFE
42 #define KE_MOUSE        0xFFFB
43 #define KE_SHIFTKEYS    0xFFFA
44 #define KE_BREAK	0xFFF0
45 
46 /*
47     status control keys
48 */
49 
50 #define KE_STATUS_ALT		'\x01'	/**< CTRL+A */
51 #define KE_STATUS_CONTROL	'\x03'	/**< CTRL+C */
52 #define KE_STATUS_SHIFT		'\x13'	/**< CTRL+S */
53 #define KE_STATUS_RESET		'\x1a'	/**< CTRL+Z */
54 #define KE_C_O			'\x0f'  /**< CTRL+O */
55 
56 /*
57 
58 */
59 
60 #define KE_ESCAPE	'\x1b'
61 #define KE_SPACE	' '
62 #define KE_TAB		'\t'
63 #define KE_ENTER	'\n'
64 #define KE_ENTER2	'\r'
65 #define KE_BKSPACE1	'\x08'
66 #define KE_BKSPACE2	'\x7f'
67 
68 /*
69     All non-symbol keys (function keys, arrows, etc) must be xx00
70     because of biew dos-dependent key treatment (will be fixed)
71 */
72 
73 #ifdef	_SLANG_
74 #include <slang.h>
75 #define _2B(x)	((((x) & 0xff) << 8) + (((x) & 0xf00) << 4) * 4)
76 /* #define KE_ENTER	_2B(SL_KEY_ENTER) */
77 #define KE_BKSPACE	_2B(SL_KEY_BACKSPACE)
78 #define KE_DOWNARROW	_2B(SL_KEY_DOWN)
79 #define KE_UPARROW	_2B(SL_KEY_UP)
80 #define KE_LEFTARROW	_2B(SL_KEY_LEFT)
81 #define KE_RIGHTARROW	_2B(SL_KEY_RIGHT)
82 #define KE_HOME		_2B(SL_KEY_HOME)
83 #define KE_END		_2B(SL_KEY_END)
84 #define KE_PGUP		_2B(SL_KEY_PPAGE)
85 #define KE_PGDN		_2B(SL_KEY_NPAGE)
86 #define KE_INS		_2B(SL_KEY_IC)
87 #define KE_DEL		_2B(SL_KEY_DELETE)
88 #define KE_F(x)		_2B(SL_KEY_F(x))
89 #endif
90 
91 
92 #ifdef	_CURSES_
93 #include <curses.h>
94 #define _2B(x)	(((x) & 0xff) << 8)
95 /* #define KE_ENTER	_2B(KEY_ENTER) */
96 #define KE_BKSPACE	_2B(KEY_BACKSPACE)
97 #define KE_DOWNARROW	_2B(KEY_DOWN)
98 #define KE_UPARROW	_2B(KEY_UP)
99 #define KE_LEFTARROW	_2B(KEY_LEFT)
100 #define KE_RIGHTARROW	_2B(KEY_RIGHT)
101 #define KE_HOME		_2B(KEY_HOME)
102 #define KE_END		_2B(KEY_END)
103 #define KE_PGUP		_2B(KEY_PPAGE)
104 #define KE_PGDN		_2B(KEY_NPAGE)
105 #define KE_INS		_2B(KEY_IC)
106 #define KE_DEL		_2B(KEY_DC)
107 #define KE_F(x)		_2B(KEY_F(x))
108 #endif
109 
110 
111 /*
112     these are not real keyboard codes on vt100,
113     GetKey() translates escape sequence to these values
114 */
115 
116 #ifdef	_VT100_
117 #define KE_BKSPACE	'\x08'
118 #define KE_DOWNARROW	0x5000
119 #define KE_UPARROW	0x4800
120 #define KE_LEFTARROW	0x4b00
121 #define KE_RIGHTARROW	0x4d00
122 #define KE_HOME		0x4700
123 #define KE_END		0x4f00
124 #define KE_PGUP		0x4900
125 #define KE_PGDN		0x5100
126 #define KE_INS		0x5200
127 #define KE_DEL		0x5300
128 #define KE_F(x)		((0x3a + (x)) << 8)
129 #endif
130 
131 /*
132     do not edit below
133 */
134 
135 #define ADD_CONTROL	0x010000
136 #define ADD_ALT		0x020000
137 #define ADD_SHIFT	0x040000
138 
139 #define KE_CTL_LEFTARROW	(KE_LEFTARROW | ADD_CONTROL)
140 #define KE_CTL_RIGHTARROW	(KE_RIGHTARROW | ADD_CONTROL)
141 
142 #define KE_SHIFT_TAB	(KE_TAB | ADD_CONTROL)
143 #define KE_CTL_BKSPACE	(KE_BKSPACE | ADD_CONTROL)
144 #define KE_CTL_ENTER	(KE_ENTER | ADD_CONTROL)
145 #define KE_CTL_BREAK	(KE_BREAK | ADD_CONTROL)
146 
147 #define KE_CTL_PGDN	(KE_PGDN | ADD_CONTROL)
148 #define KE_CTL_PGUP	(KE_PGUP | ADD_CONTROL)
149 #define KE_CTL_HOME	(KE_HOME | ADD_CONTROL)
150 #define KE_CTL_END	(KE_END | ADD_CONTROL)
151 
152 #define KE_SHIFT_F(x)	(KE_F(x) | ADD_SHIFT)
153 #define KE_CTL_F(x)	(KE_F(x) | ADD_CONTROL)
154 #define KE_ALT_F(x)	(KE_F(x) | ADD_ALT)
155 
156 /*
157 #define KE_ALT_(x)	( (x) | ADD_ALT)
158 #define KE_CTL_(x)	( (x) | ADD_CONTROL)
159 */
160 
161 #define SCAN_A  0x1e
162 #define SCAN_B  0x30
163 #define SCAN_C  0x2e
164 #define SCAN_D  0x20
165 #define SCAN_E  0x12
166 #define SCAN_F  0x21
167 #define SCAN_G  0x22
168 #define SCAN_H  0x23
169 #define SCAN_I  0x17
170 #define SCAN_J  0x24
171 #define SCAN_K  0x25
172 #define SCAN_L  0x26
173 #define SCAN_M  0x31
174 #define SCAN_N  0x32
175 #define SCAN_O  0x18
176 #define SCAN_P  0x19
177 #define SCAN_Q  0x10
178 #define SCAN_R  0x13
179 #define SCAN_S  0x1f
180 #define SCAN_T  0x14
181 #define SCAN_U  0x16
182 #define SCAN_V  0x2f
183 #define SCAN_W  0x11
184 #define SCAN_X  0x2d
185 #define SCAN_Y  0x15
186 #define SCAN_Z  0x2c
187 
188 #define ENUM_A  0x01
189 #define ENUM_B  0x02
190 #define ENUM_C  0x03
191 #define ENUM_D  0x04
192 #define ENUM_E  0x05
193 #define ENUM_F  0x06
194 #define ENUM_G  0x07
195 #define ENUM_H  0x08
196 #define ENUM_I  0x09
197 #define ENUM_J  0x0a
198 #define ENUM_K  0x0b
199 #define ENUM_L  0x0c
200 #define ENUM_M  0x0d
201 #define ENUM_N  0x0e
202 #define ENUM_O  0x0f
203 #define ENUM_P  0x10
204 #define ENUM_Q  0x11
205 #define ENUM_R  0x12
206 #define ENUM_S  0x13
207 #define ENUM_T  0x14
208 #define ENUM_U  0x15
209 #define ENUM_V  0x16
210 #define ENUM_W  0x17
211 #define ENUM_X  0x18
212 #define ENUM_Y  0x19
213 #define ENUM_Z  0x1a
214 
215 #define __SCAN_(x) (SCAN_##x)
216 #define __ENUM_(x) (ENUM_##x)
217 
218 #define KE_CTL_(x) ((((__SCAN_(x) << 8) & 0xFF00) | ((__ENUM_(x)-__ENUM_(A)+1) & 0x00FF)) | ADD_CONTROL)
219 #define KE_ALT_(x) ((((__SCAN_(x) << 8) & 0xFF00) | ADD_ALT)
220 
221 #endif	/* __KBD_CODE_H */
222