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_PERCENT     = 37,      // %
00054     KEYCODE_AMPERSAND   = 38,      // &
00055     KEYCODE_QUOTE       = 39,      // '
00056     KEYCODE_LEFTPAREN   = 40,      // (
00057     KEYCODE_RIGHTPAREN  = 41,      // )
00058     KEYCODE_ASTERISK    = 42,      // *
00059     KEYCODE_PLUS        = 43,      // +
00060     KEYCODE_COMMA       = 44,      // ,
00061     KEYCODE_MINUS       = 45,      // -
00062     KEYCODE_PERIOD      = 46,      // .
00063     KEYCODE_SLASH       = 47,      // /
00064     KEYCODE_0           = 48,
00065     KEYCODE_1           = 49,
00066     KEYCODE_2           = 50,
00067     KEYCODE_3           = 51,
00068     KEYCODE_4           = 52,
00069     KEYCODE_5           = 53,
00070     KEYCODE_6           = 54,
00071     KEYCODE_7           = 55,
00072     KEYCODE_8           = 56,
00073     KEYCODE_9           = 57,
00074     KEYCODE_COLON       = 58,      // :
00075     KEYCODE_SEMICOLON   = 59,      // ;
00076     KEYCODE_LESS        = 60,      // <
00077     KEYCODE_EQUALS      = 61,      // =
00078     KEYCODE_GREATER     = 62,      // >
00079     KEYCODE_QUESTION    = 63,      // ?
00080     KEYCODE_AT          = 64,      // @
00081 
00082     KEYCODE_LEFTBRACKET = 91,      // [
00083     KEYCODE_BACKSLASH   = 92,      // "\"
00084     KEYCODE_RIGHTBRACKET= 93,      // ]
00085     KEYCODE_CARET       = 94,      // ^
00086     KEYCODE_UNDERSCORE  = 95,      // _
00087     KEYCODE_BACKQUOTE   = 96,      // `
00088     KEYCODE_a           = 97,
00089     KEYCODE_b           = 98,
00090     KEYCODE_c           = 99,
00091     KEYCODE_d           = 100,
00092     KEYCODE_e           = 101,
00093     KEYCODE_f           = 102,
00094     KEYCODE_g           = 103,
00095     KEYCODE_h           = 104,
00096     KEYCODE_i           = 105,
00097     KEYCODE_j           = 106,
00098     KEYCODE_k           = 107,
00099     KEYCODE_l           = 108,
00100     KEYCODE_m           = 109,
00101     KEYCODE_n           = 110,
00102     KEYCODE_o           = 111,
00103     KEYCODE_p           = 112,
00104     KEYCODE_q           = 113,
00105     KEYCODE_r           = 114,
00106     KEYCODE_s           = 115,
00107     KEYCODE_t           = 116,
00108     KEYCODE_u           = 117,
00109     KEYCODE_v           = 118,
00110     KEYCODE_w           = 119,
00111     KEYCODE_x           = 120,
00112     KEYCODE_y           = 121,
00113     KEYCODE_z           = 122,
00114     KEYCODE_DELETE      = 127,
00115     KEYCODE_TILDE       = 176,      // ~
00116 
00117     // Numeric keypad
00118     KEYCODE_KP0         = 256,
00119     KEYCODE_KP1         = 257,
00120     KEYCODE_KP2         = 258,
00121     KEYCODE_KP3         = 259,
00122     KEYCODE_KP4         = 260,
00123     KEYCODE_KP5         = 261,
00124     KEYCODE_KP6         = 262,
00125     KEYCODE_KP7         = 263,
00126     KEYCODE_KP8         = 264,
00127     KEYCODE_KP9         = 265,
00128     KEYCODE_KP_PERIOD   = 266,
00129     KEYCODE_KP_DIVIDE   = 267,
00130     KEYCODE_KP_MULTIPLY = 268,
00131     KEYCODE_KP_MINUS    = 269,
00132     KEYCODE_KP_PLUS     = 270,
00133     KEYCODE_KP_ENTER    = 271,
00134     KEYCODE_KP_EQUALS   = 272,
00135 
00136     // Arrows + Home/End pad
00137     KEYCODE_UP          = 273,
00138     KEYCODE_DOWN        = 274,
00139     KEYCODE_RIGHT       = 275,
00140     KEYCODE_LEFT        = 276,
00141     KEYCODE_INSERT      = 277,
00142     KEYCODE_HOME        = 278,
00143     KEYCODE_END         = 279,
00144     KEYCODE_PAGEUP      = 280,
00145     KEYCODE_PAGEDOWN    = 281,
00146 
00147     // Function keys
00148     KEYCODE_F1          = 282,
00149     KEYCODE_F2          = 283,
00150     KEYCODE_F3          = 284,
00151     KEYCODE_F4          = 285,
00152     KEYCODE_F5          = 286,
00153     KEYCODE_F6          = 287,
00154     KEYCODE_F7          = 288,
00155     KEYCODE_F8          = 289,
00156     KEYCODE_F9          = 290,
00157     KEYCODE_F10         = 291,
00158     KEYCODE_F11         = 292,
00159     KEYCODE_F12         = 293,
00160     KEYCODE_F13         = 294,
00161     KEYCODE_F14         = 295,
00162     KEYCODE_F15         = 296,
00163     KEYCODE_F16         = 297,
00164     KEYCODE_F17         = 298,
00165     KEYCODE_F18         = 299,
00166 
00167     // Key state modifier keys
00168     KEYCODE_NUMLOCK     = 300,
00169     KEYCODE_CAPSLOCK    = 301,
00170     KEYCODE_SCROLLOCK   = 302,
00171     KEYCODE_RSHIFT      = 303,
00172     KEYCODE_LSHIFT      = 304,
00173     KEYCODE_RCTRL       = 305,
00174     KEYCODE_LCTRL       = 306,
00175     KEYCODE_RALT        = 307,
00176     KEYCODE_LALT        = 308,
00177     KEYCODE_RMETA       = 309,
00178     KEYCODE_LMETA       = 310,
00179     KEYCODE_LSUPER      = 311,      // Left "Windows" key
00180     KEYCODE_RSUPER      = 312,      // Right "Windows" key
00181     KEYCODE_MODE        = 313,      // "Alt Gr" key
00182     KEYCODE_COMPOSE     = 314,      // Multi-key compose key
00183 
00184     // Miscellaneous function keys
00185     KEYCODE_HELP        = 315,
00186     KEYCODE_PRINT       = 316,
00187     KEYCODE_SYSREQ      = 317,
00188     KEYCODE_BREAK       = 318,
00189     KEYCODE_MENU        = 319,
00190     KEYCODE_POWER       = 320,      // Power Macintosh power key
00191     KEYCODE_EURO        = 321,      // Some european keyboards
00192     KEYCODE_UNDO        = 322,      // Atari keyboard has Undo
00193     KEYCODE_SLEEP       = 323,
00194     KEYCODE_MUTE        = 324,
00195     KEYCODE_EJECT       = 325,
00196     KEYCODE_VOLUMEUP    = 326,
00197     KEYCODE_VOLUMEDOWN  = 327,
00198     KEYCODE_LEFTSOFT    = 328,
00199     KEYCODE_RIGHTSOFT   = 329,
00200     KEYCODE_CALL        = 330,
00201     KEYCODE_HANGUP      = 331,
00202     KEYCODE_CAMERA      = 332,
00203     KEYCODE_WWW         = 333,
00204     KEYCODE_MAIL        = 334,
00205     KEYCODE_CALCULATOR  = 335,
00206     KEYCODE_CUT         = 336,
00207     KEYCODE_COPY        = 337,
00208     KEYCODE_PASTE       = 338,
00209     KEYCODE_SELECT      = 339,
00210     KEYCODE_CANCEL      = 340,
00211 
00212     // Action keys
00213     KEYCODE_AC_SEARCH    = 341,
00214     KEYCODE_AC_HOME      = 342,
00215     KEYCODE_AC_BACK      = 343,
00216     KEYCODE_AC_FORWARD   = 344,
00217     KEYCODE_AC_STOP      = 345,
00218     KEYCODE_AC_REFRESH   = 346,
00219     KEYCODE_AC_BOOKMARKS = 347,
00220 
00221     // Audio keys
00222     KEYCODE_AUDIONEXT        = 348,
00223     KEYCODE_AUDIOPREV        = 349,
00224     KEYCODE_AUDIOSTOP        = 350,
00225     KEYCODE_AUDIOPLAY        = 351,
00226     KEYCODE_AUDIOPAUSE       = 352,
00227     KEYCODE_AUDIOPLAYPAUSE   = 353,
00228     KEYCODE_AUDIOMUTE        = 354,
00229     KEYCODE_AUDIOREWIND      = 355,
00230     KEYCODE_AUDIOFASTFORWARD = 356,
00231 
00232     KEYCODE_LAST
00233 };
00234 
00242 enum {
00243     ASCII_BACKSPACE     = 8,
00244     ASCII_TAB           = 9,
00245     ASCII_RETURN        = 13,
00246     ASCII_ESCAPE        = 27,
00247     ASCII_SPACE         = 32,
00248 
00249     ASCII_F1            = 315,
00250     ASCII_F2            = 316,
00251     ASCII_F3            = 317,
00252     ASCII_F4            = 318,
00253     ASCII_F5            = 319,
00254     ASCII_F6            = 320,
00255     ASCII_F7            = 321,
00256     ASCII_F8            = 322,
00257     ASCII_F9            = 323,
00258     ASCII_F10           = 324,
00259     ASCII_F11           = 325,
00260     ASCII_F12           = 326
00261 };
00262 
00266 enum {
00267     // Non-sticky modifier flags
00268     KBD_CTRL  = 1 << 0,
00269     KBD_ALT   = 1 << 1,
00270     KBD_SHIFT = 1 << 2,
00271     KBD_META  = 1 << 3,
00272     KBD_NON_STICKY = (KBD_CTRL|KBD_ALT|KBD_SHIFT|KBD_META),
00273 
00274     // Sticky modifier flags
00275     KBD_NUM   = 1 << 4,
00276     KBD_CAPS  = 1 << 5,
00277     KBD_SCRL  = 1 << 6,
00278     KBD_STICKY = (KBD_NUM|KBD_CAPS|KBD_SCRL)
00279 
00280 };
00281 
00285 struct KeyState {
00290     KeyCode keycode;
00291 
00301     uint16 ascii;
00302 
00314     byte flags;
00315 
00316     KeyState(KeyCode kc = KEYCODE_INVALID) {
00317         keycode = kc;
00318         ascii = (uint16)kc;
00319         flags = 0;
00320     }
00321 
00322     KeyState(KeyCode kc, uint16 asc, byte f = 0) {
00323         keycode = kc;
00324         ascii = asc;
00325         flags = f;
00326     }
00327 
00328     void reset() {
00329         keycode = KEYCODE_INVALID;
00330         ascii = flags = 0;
00331     }
00332 
00342     bool hasFlags(byte f) const {
00343         assert(!(f & KBD_STICKY));
00344         return f == (flags & ~KBD_STICKY);
00345     }
00346 
00352     bool operator==(const KeyState &x) const {
00353         // Intentionally ignore ASCII, as the keycode and non-sticky flag
00354         // combination should suffice.
00355         return keycode == x.keycode && hasFlags(x.flags & ~KBD_STICKY);
00356     }
00357 };
00358 
00359 } // End of namespace Common
00360 
00361 #endif


Generated on Sat Aug 8 2020 05:01:09 for ResidualVM by doxygen 1.7.1
curved edge   curved edge