ScummVM API documentation
keyboard.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef COMMON_KEYBOARD_H
23 #define COMMON_KEYBOARD_H
24 
25 #include "common/scummsys.h"
26 
27 #if defined(__amigaos4__) || defined(__MORPHOS__)
28  // KEYCODE_LESS and KEYCODE_GREATER are already defined in AmigaOS and MorphOS,
29  // inside "include/include_h/intuition/intuition.h" (fixes bug #5532)
30  #if defined(KEYCODE_LESS) && defined(KEYCODE_GREATER)
31  #undef KEYCODE_LESS
32  #undef KEYCODE_GREATER
33  #endif
34 #endif
35 
36 namespace Common {
37 
48 enum KeyCode {
49  KEYCODE_INVALID = 0,
50 
51  KEYCODE_BACKSPACE = 8,
52  KEYCODE_TAB = 9,
53  KEYCODE_CLEAR = 12,
54  KEYCODE_RETURN = 13,
55  KEYCODE_PAUSE = 19,
56  KEYCODE_ESCAPE = 27,
57  KEYCODE_SPACE = 32,
58  KEYCODE_EXCLAIM = 33, // !
59  KEYCODE_QUOTEDBL = 34, // "
60  KEYCODE_HASH = 35, // #
61  KEYCODE_DOLLAR = 36, // $
62  KEYCODE_PERCENT = 37, // %
63  KEYCODE_AMPERSAND = 38, // &
64  KEYCODE_QUOTE = 39, // '
65  KEYCODE_LEFTPAREN = 40, // (
66  KEYCODE_RIGHTPAREN = 41, // )
67  KEYCODE_ASTERISK = 42, // *
68  KEYCODE_PLUS = 43, // +
69  KEYCODE_COMMA = 44, // ,
70  KEYCODE_MINUS = 45, // -
71  KEYCODE_PERIOD = 46, // .
72  KEYCODE_SLASH = 47, // /
73  KEYCODE_0 = 48,
74  KEYCODE_1 = 49,
75  KEYCODE_2 = 50,
76  KEYCODE_3 = 51,
77  KEYCODE_4 = 52,
78  KEYCODE_5 = 53,
79  KEYCODE_6 = 54,
80  KEYCODE_7 = 55,
81  KEYCODE_8 = 56,
82  KEYCODE_9 = 57,
83  KEYCODE_COLON = 58, // :
84  KEYCODE_SEMICOLON = 59, // ;
85  KEYCODE_LESS = 60, // <
86  KEYCODE_EQUALS = 61, // =
87  KEYCODE_GREATER = 62, // >
88  KEYCODE_QUESTION = 63, // ?
89  KEYCODE_AT = 64, // @
90 
91  KEYCODE_LEFTBRACKET = 91, // [
92  KEYCODE_BACKSLASH = 92, // "\"
93  KEYCODE_RIGHTBRACKET= 93, // ]
94  KEYCODE_CARET = 94, // ^
95  KEYCODE_UNDERSCORE = 95, // _
96  KEYCODE_BACKQUOTE = 96, // `
97  KEYCODE_a = 97,
98  KEYCODE_b = 98,
99  KEYCODE_c = 99,
100  KEYCODE_d = 100,
101  KEYCODE_e = 101,
102  KEYCODE_f = 102,
103  KEYCODE_g = 103,
104  KEYCODE_h = 104,
105  KEYCODE_i = 105,
106  KEYCODE_j = 106,
107  KEYCODE_k = 107,
108  KEYCODE_l = 108,
109  KEYCODE_m = 109,
110  KEYCODE_n = 110,
111  KEYCODE_o = 111,
112  KEYCODE_p = 112,
113  KEYCODE_q = 113,
114  KEYCODE_r = 114,
115  KEYCODE_s = 115,
116  KEYCODE_t = 116,
117  KEYCODE_u = 117,
118  KEYCODE_v = 118,
119  KEYCODE_w = 119,
120  KEYCODE_x = 120,
121  KEYCODE_y = 121,
122  KEYCODE_z = 122,
123  KEYCODE_DELETE = 127,
124  KEYCODE_TILDE = 176, // ~
125 
126  // Numeric keypad
127  KEYCODE_KP0 = 256,
128  KEYCODE_KP1 = 257,
129  KEYCODE_KP2 = 258,
130  KEYCODE_KP3 = 259,
131  KEYCODE_KP4 = 260,
132  KEYCODE_KP5 = 261,
133  KEYCODE_KP6 = 262,
134  KEYCODE_KP7 = 263,
135  KEYCODE_KP8 = 264,
136  KEYCODE_KP9 = 265,
137  KEYCODE_KP_PERIOD = 266,
138  KEYCODE_KP_DIVIDE = 267,
139  KEYCODE_KP_MULTIPLY = 268,
140  KEYCODE_KP_MINUS = 269,
141  KEYCODE_KP_PLUS = 270,
142  KEYCODE_KP_ENTER = 271,
143  KEYCODE_KP_EQUALS = 272,
144 
145  // Arrows + Home/End pad
146  KEYCODE_UP = 273,
147  KEYCODE_DOWN = 274,
148  KEYCODE_RIGHT = 275,
149  KEYCODE_LEFT = 276,
150  KEYCODE_INSERT = 277,
151  KEYCODE_HOME = 278,
152  KEYCODE_END = 279,
153  KEYCODE_PAGEUP = 280,
154  KEYCODE_PAGEDOWN = 281,
155 
156  // Function keys
157  KEYCODE_F1 = 282,
158  KEYCODE_F2 = 283,
159  KEYCODE_F3 = 284,
160  KEYCODE_F4 = 285,
161  KEYCODE_F5 = 286,
162  KEYCODE_F6 = 287,
163  KEYCODE_F7 = 288,
164  KEYCODE_F8 = 289,
165  KEYCODE_F9 = 290,
166  KEYCODE_F10 = 291,
167  KEYCODE_F11 = 292,
168  KEYCODE_F12 = 293,
169  KEYCODE_F13 = 294,
170  KEYCODE_F14 = 295,
171  KEYCODE_F15 = 296,
172  KEYCODE_F16 = 297,
173  KEYCODE_F17 = 298,
174  KEYCODE_F18 = 299,
175 
176  // Key state modifier keys
177  KEYCODE_NUMLOCK = 300,
178  KEYCODE_CAPSLOCK = 301,
179  KEYCODE_SCROLLOCK = 302,
180  KEYCODE_RSHIFT = 303,
181  KEYCODE_LSHIFT = 304,
182  KEYCODE_RCTRL = 305,
183  KEYCODE_LCTRL = 306,
184  KEYCODE_RALT = 307,
185  KEYCODE_LALT = 308,
186  KEYCODE_RMETA = 309,
187  KEYCODE_LMETA = 310,
188  KEYCODE_LSUPER = 311, // Left "Windows" key
189  KEYCODE_RSUPER = 312, // Right "Windows" key
190  KEYCODE_MODE = 313, // "Alt Gr" key
191  KEYCODE_COMPOSE = 314, // Multi-key compose key
192 
193  // Miscellaneous function keys
194  KEYCODE_HELP = 315,
195  KEYCODE_PRINT = 316,
196  KEYCODE_SYSREQ = 317,
197  KEYCODE_BREAK = 318,
198  KEYCODE_MENU = 319,
199  KEYCODE_POWER = 320, // Power Macintosh power key
200  KEYCODE_EURO = 321, // Some european keyboards
201  KEYCODE_UNDO = 322, // Atari keyboard has Undo
202  KEYCODE_SLEEP = 323,
203  KEYCODE_MUTE = 324,
204  KEYCODE_EJECT = 325,
205  KEYCODE_VOLUMEUP = 326,
206  KEYCODE_VOLUMEDOWN = 327,
207  KEYCODE_LEFTSOFT = 328,
208  KEYCODE_RIGHTSOFT = 329,
209  KEYCODE_CALL = 330,
210  KEYCODE_HANGUP = 331,
211  KEYCODE_CAMERA = 332,
212  KEYCODE_WWW = 333,
213  KEYCODE_MAIL = 334,
214  KEYCODE_CALCULATOR = 335,
215  KEYCODE_CUT = 336,
216  KEYCODE_COPY = 337,
217  KEYCODE_PASTE = 338,
218  KEYCODE_SELECT = 339,
219  KEYCODE_CANCEL = 340,
220 
221  // Action keys
222  KEYCODE_AC_SEARCH = 341,
223  KEYCODE_AC_HOME = 342,
224  KEYCODE_AC_BACK = 343,
225  KEYCODE_AC_FORWARD = 344,
226  KEYCODE_AC_STOP = 345,
227  KEYCODE_AC_REFRESH = 346,
228  KEYCODE_AC_BOOKMARKS = 347,
229 
230  // Audio keys
231  KEYCODE_AUDIONEXT = 348,
232  KEYCODE_AUDIOPREV = 349,
233  KEYCODE_AUDIOSTOP = 350,
234  KEYCODE_AUDIOPLAY = 351,
235  KEYCODE_AUDIOPAUSE = 352,
236  KEYCODE_AUDIOPLAYPAUSE = 353,
237  KEYCODE_AUDIOMUTE = 354,
238  KEYCODE_AUDIOREWIND = 355,
239  KEYCODE_AUDIOFASTFORWARD = 356,
240 
241  KEYCODE_LAST
242 };
243 
251 enum {
252  ASCII_BACKSPACE = 8,
253  ASCII_TAB = 9,
254  ASCII_RETURN = 13,
255  ASCII_ESCAPE = 27,
256  ASCII_SPACE = 32,
257 
258  ASCII_F1 = 315,
259  ASCII_F2 = 316,
260  ASCII_F3 = 317,
261  ASCII_F4 = 318,
262  ASCII_F5 = 319,
263  ASCII_F6 = 320,
264  ASCII_F7 = 321,
265  ASCII_F8 = 322,
266  ASCII_F9 = 323,
267  ASCII_F10 = 324,
268  ASCII_F11 = 325,
269  ASCII_F12 = 326
270 };
271 
275 enum {
276  // Non-sticky modifier flags
277  KBD_CTRL = 1 << 0,
278  KBD_ALT = 1 << 1,
279  KBD_SHIFT = 1 << 2,
280  KBD_META = 1 << 3,
281  KBD_NON_STICKY = (KBD_CTRL|KBD_ALT|KBD_SHIFT|KBD_META),
282 
283  // Sticky modifier flags
284  KBD_NUM = 1 << 4,
285  KBD_CAPS = 1 << 5,
286  KBD_SCRL = 1 << 6,
287  KBD_STICKY = (KBD_NUM|KBD_CAPS|KBD_SCRL)
288 
289 };
290 
294 struct KeyState {
299  KeyCode keycode;
300 
310  uint16 ascii;
311 
323  byte flags;
324 
325  KeyState(KeyCode kc = KEYCODE_INVALID) {
326  keycode = kc;
327  ascii = (uint16)kc;
328  flags = 0;
329  }
330 
331  KeyState(KeyCode kc, uint16 asc, byte f = 0) {
332  keycode = kc;
333  ascii = asc;
334  flags = f;
335  }
336 
337  void reset() {
338  keycode = KEYCODE_INVALID;
339  ascii = flags = 0;
340  }
341 
351  bool hasFlags(byte f) const {
352  assert(!(f & KBD_STICKY));
353  return f == (flags & ~KBD_STICKY);
354  }
355 
361  bool operator==(const KeyState &x) const {
362  // Intentionally ignore ASCII, as the keycode and non-sticky flag
363  // combination should suffice.
364  return keycode == x.keycode && hasFlags(x.flags & ~KBD_STICKY);
365  }
366 };
367 
370 } // End of namespace Common
371 
372 #endif
byte flags
Definition: keyboard.h:323
bool hasFlags(byte f) const
Definition: keyboard.h:351
KeyCode keycode
Definition: keyboard.h:299
Definition: algorithm.h:29
Definition: keyboard.h:294
uint16 ascii
Definition: keyboard.h:310
bool operator==(const KeyState &x) const
Definition: keyboard.h:361