ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

keyboard.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_KEYBOARD_H
00024 #define COMMON_KEYBOARD_H
00025 
00026 #include "common/scummsys.h"
00027 
00028 #if defined(__amigaos4__)
00029 // KEYCODE_LESS and KEYCODE_GREATER are already defined in AmigaOS, inside
00030 // include/include_h/intuition/intuition.h (bug #3121350)
00031 #if defined(KEYCODE_LESS) && defined(KEYCODE_GREATER)
00032 #undef KEYCODE_LESS
00033 #undef KEYCODE_GREATER
00034 #endif
00035 #endif
00036 
00037 namespace Common {
00038 
00039 enum KeyCode {
00040     KEYCODE_INVALID     = 0,
00041 
00042     KEYCODE_BACKSPACE   = 8,
00043     KEYCODE_TAB         = 9,
00044     KEYCODE_CLEAR       = 12,
00045     KEYCODE_RETURN      = 13,
00046     KEYCODE_PAUSE       = 19,
00047     KEYCODE_ESCAPE      = 27,
00048     KEYCODE_SPACE       = 32,
00049     KEYCODE_EXCLAIM     = 33,      // !
00050     KEYCODE_QUOTEDBL    = 34,      // "
00051     KEYCODE_HASH        = 35,      // #
00052     KEYCODE_DOLLAR      = 36,      // $
00053     KEYCODE_AMPERSAND   = 38,      // &
00054     KEYCODE_QUOTE       = 39,      // '
00055     KEYCODE_LEFTPAREN   = 40,
00056     KEYCODE_RIGHTPAREN  = 41,
00057     KEYCODE_ASTERISK    = 42,      // *
00058     KEYCODE_PLUS        = 43,
00059     KEYCODE_COMMA       = 44,
00060     KEYCODE_MINUS       = 45,
00061     KEYCODE_PERIOD      = 46,
00062     KEYCODE_SLASH       = 47,
00063     KEYCODE_0           = 48,
00064     KEYCODE_1           = 49,
00065     KEYCODE_2           = 50,
00066     KEYCODE_3           = 51,
00067     KEYCODE_4           = 52,
00068     KEYCODE_5           = 53,
00069     KEYCODE_6           = 54,
00070     KEYCODE_7           = 55,
00071     KEYCODE_8           = 56,
00072     KEYCODE_9           = 57,
00073     KEYCODE_COLON       = 58,
00074     KEYCODE_SEMICOLON   = 59,
00075     KEYCODE_LESS        = 60,
00076     KEYCODE_EQUALS      = 61,
00077     KEYCODE_GREATER     = 62,
00078     KEYCODE_QUESTION    = 63,
00079     KEYCODE_AT          = 64,
00080 
00081     KEYCODE_LEFTBRACKET = 91,
00082     KEYCODE_BACKSLASH   = 92,
00083     KEYCODE_RIGHTBRACKET= 93,
00084     KEYCODE_CARET       = 94,
00085     KEYCODE_UNDERSCORE  = 95,
00086     KEYCODE_BACKQUOTE   = 96,
00087     KEYCODE_a           = 97,
00088     KEYCODE_b           = 98,
00089     KEYCODE_c           = 99,
00090     KEYCODE_d           = 100,
00091     KEYCODE_e           = 101,
00092     KEYCODE_f           = 102,
00093     KEYCODE_g           = 103,
00094     KEYCODE_h           = 104,
00095     KEYCODE_i           = 105,
00096     KEYCODE_j           = 106,
00097     KEYCODE_k           = 107,
00098     KEYCODE_l           = 108,
00099     KEYCODE_m           = 109,
00100     KEYCODE_n           = 110,
00101     KEYCODE_o           = 111,
00102     KEYCODE_p           = 112,
00103     KEYCODE_q           = 113,
00104     KEYCODE_r           = 114,
00105     KEYCODE_s           = 115,
00106     KEYCODE_t           = 116,
00107     KEYCODE_u           = 117,
00108     KEYCODE_v           = 118,
00109     KEYCODE_w           = 119,
00110     KEYCODE_x           = 120,
00111     KEYCODE_y           = 121,
00112     KEYCODE_z           = 122,
00113     KEYCODE_DELETE      = 127,
00114     KEYCODE_TILDE       = 176,      // ~
00115 
00116     // Numeric keypad
00117     KEYCODE_KP0         = 256,
00118     KEYCODE_KP1         = 257,
00119     KEYCODE_KP2         = 258,
00120     KEYCODE_KP3         = 259,
00121     KEYCODE_KP4         = 260,
00122     KEYCODE_KP5         = 261,
00123     KEYCODE_KP6         = 262,
00124     KEYCODE_KP7         = 263,
00125     KEYCODE_KP8         = 264,
00126     KEYCODE_KP9         = 265,
00127     KEYCODE_KP_PERIOD   = 266,
00128     KEYCODE_KP_DIVIDE   = 267,
00129     KEYCODE_KP_MULTIPLY = 268,
00130     KEYCODE_KP_MINUS    = 269,
00131     KEYCODE_KP_PLUS     = 270,
00132     KEYCODE_KP_ENTER    = 271,
00133     KEYCODE_KP_EQUALS   = 272,
00134 
00135     // Arrows + Home/End pad
00136     KEYCODE_UP          = 273,
00137     KEYCODE_DOWN        = 274,
00138     KEYCODE_RIGHT       = 275,
00139     KEYCODE_LEFT        = 276,
00140     KEYCODE_INSERT      = 277,
00141     KEYCODE_HOME        = 278,
00142     KEYCODE_END         = 279,
00143     KEYCODE_PAGEUP      = 280,
00144     KEYCODE_PAGEDOWN    = 281,
00145 
00146     // Function keys
00147     KEYCODE_F1          = 282,
00148     KEYCODE_F2          = 283,
00149     KEYCODE_F3          = 284,
00150     KEYCODE_F4          = 285,
00151     KEYCODE_F5          = 286,
00152     KEYCODE_F6          = 287,
00153     KEYCODE_F7          = 288,
00154     KEYCODE_F8          = 289,
00155     KEYCODE_F9          = 290,
00156     KEYCODE_F10         = 291,
00157     KEYCODE_F11         = 292,
00158     KEYCODE_F12         = 293,
00159     KEYCODE_F13         = 294,
00160     KEYCODE_F14         = 295,
00161     KEYCODE_F15         = 296,
00162 
00163     // Key state modifier keys
00164     KEYCODE_NUMLOCK     = 300,
00165     KEYCODE_CAPSLOCK    = 301,
00166     KEYCODE_SCROLLOCK   = 302,
00167     KEYCODE_RSHIFT      = 303,
00168     KEYCODE_LSHIFT      = 304,
00169     KEYCODE_RCTRL       = 305,
00170     KEYCODE_LCTRL       = 306,
00171     KEYCODE_RALT        = 307,
00172     KEYCODE_LALT        = 308,
00173     KEYCODE_RMETA       = 309,
00174     KEYCODE_LMETA       = 310,
00175     KEYCODE_LSUPER      = 311,      // Left "Windows" key
00176     KEYCODE_RSUPER      = 312,      // Right "Windows" key
00177     KEYCODE_MODE        = 313,      // "Alt Gr" key
00178     KEYCODE_COMPOSE     = 314,      // Multi-key compose key
00179 
00180     // Miscellaneous function keys
00181     KEYCODE_HELP        = 315,
00182     KEYCODE_PRINT       = 316,
00183     KEYCODE_SYSREQ      = 317,
00184     KEYCODE_BREAK       = 318,
00185     KEYCODE_MENU        = 319,
00186     KEYCODE_POWER       = 320,      // Power Macintosh power key
00187     KEYCODE_EURO        = 321,      // Some european keyboards
00188     KEYCODE_UNDO        = 322       // Atari keyboard has Undo
00189 };
00190 
00198 enum {
00199     ASCII_BACKSPACE     = 8,
00200     ASCII_TAB           = 9,
00201     ASCII_RETURN        = 13,
00202     ASCII_ESCAPE        = 27,
00203     ASCII_SPACE         = 32,
00204 
00205     ASCII_F1            = 315,
00206     ASCII_F2            = 316,
00207     ASCII_F3            = 317,
00208     ASCII_F4            = 318,
00209     ASCII_F5            = 319,
00210     ASCII_F6            = 320,
00211     ASCII_F7            = 321,
00212     ASCII_F8            = 322,
00213     ASCII_F9            = 323,
00214     ASCII_F10           = 324,
00215     ASCII_F11           = 325,
00216     ASCII_F12           = 326
00217 };
00218 
00222 enum {
00223     // Non-sticky modifier flags
00224     KBD_CTRL  = 1 << 0,
00225     KBD_ALT   = 1 << 1,
00226     KBD_SHIFT = 1 << 2,
00227     KBD_META  = 1 << 3,
00228     KBD_NON_STICKY = (KBD_CTRL|KBD_ALT|KBD_SHIFT|KBD_META),
00229 
00230     // Sticky modifier flags
00231     KBD_NUM   = 1 << 4,
00232     KBD_CAPS  = 1 << 5,
00233     KBD_SCRL  = 1 << 6,
00234     KBD_STICKY = (KBD_NUM|KBD_CAPS|KBD_SCRL)
00235 
00236 };
00237 
00241 struct KeyState {
00246     KeyCode keycode;
00247 
00257     uint16 ascii;
00258 
00270     byte flags;
00271 
00272     KeyState(KeyCode kc = KEYCODE_INVALID) {
00273         keycode = kc;
00274         ascii = (uint16)kc;
00275         flags = 0;
00276     }
00277 
00278     KeyState(KeyCode kc, uint16 asc, byte f = 0) {
00279         keycode = kc;
00280         ascii = asc;
00281         flags = f;
00282     }
00283 
00284     void reset() {
00285         keycode = KEYCODE_INVALID;
00286         ascii = flags = 0;
00287     }
00288 
00298     bool hasFlags(byte f) const {
00299         assert(!(f & KBD_STICKY));
00300         return f == (flags & ~KBD_STICKY);
00301     }
00302 
00308     bool operator==(const KeyState &x) const {
00309         // Intentionally ignore ASCII, as the keycode and non-sticky flag
00310         // combination should suffice.
00311         return keycode == x.keycode && hasFlags(x.flags & ~KBD_STICKY);
00312     }
00313 };
00314 
00315 } // End of namespace Common
00316 
00317 #endif


Generated on Sat May 25 2019 05:00:48 for ResidualVM by doxygen 1.7.1
curved edge   curved edge