# Cinder

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# include/cinder/app/KeyEvent.h

Go to the documentation of this file.

    00001 /*
    00002  Copyright (c) 2010, The Barbarian Group
    00003  All rights reserved.
    00004
    00005  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
    00006  the following conditions are met:
    00007
    00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and
    00009     the following disclaimer.
    00010     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
    00011     the following disclaimer in the documentation and/or other materials provided with the distribution.
    00012
    00013  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
    00014  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    00015  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
    00016  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
    00017  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00018  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    00019  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    00020  POSSIBILITY OF SUCH DAMAGE.
    00021 */
    00022
    00023 #pragma once
    00024
    00025 namespace cinder{
    00026 namespace app{
    00027
    00029 class KeyEvent {
    00030   public:
    00031     KeyEvent( int aCode, char aChar, unsigned int aModifiers, unsigned int aNativeKeyCode )
    00032         : mCode( aCode ), mChar( aChar ), mModifiers( aModifiers ), mNativeKeyCode( aNativeKeyCode ) {}
    00033
    00035     int     getCode() const { return mCode; }
    00037     char    getChar() const { return mChar; }
    00039     bool    isShiftDown() const { return (mModifiers & SHIFT_DOWN) ? true : false; }
    00041     bool    isAltDown() const { return (mModifiers & ALT_DOWN) ? true : false; }
    00043     bool    isControlDown() const { return (mModifiers & CTRL_DOWN) ? true : false; }
    00045     bool    isMetaDown() const { return (mModifiers & META_DOWN) ? true : false; }
    00047     bool    isAccelDown() const { return (mModifiers & ACCEL_DOWN) ? true : false; }
    00049     int     getNativeKeyCode() const { return mNativeKeyCode; }
    00050
    00052     static int      translateNativeKeyCode( int nativeKeyCode );
    00053
    00054     enum {  SHIFT_DOWN  = 0x0008,
    00055             ALT_DOWN    = 0x0010,
    00056             CTRL_DOWN   = 0x0020,
    00057             META_DOWN   = 0x0040,
    00058 #if defined( CINDER_MSW )
    00059             ACCEL_DOWN  = CTRL_DOWN
    00060 #else
    00061             ACCEL_DOWN  = META_DOWN
    00062 #endif
    00063             };
    00064
    00065     // Key codes
    00066     enum {
    00067         KEY_UNKNOWN     = 0,
    00068         KEY_FIRST       = 0,
    00069         KEY_BACKSPACE   = 8,
    00070         KEY_TAB         = 9,
    00071         KEY_CLEAR       = 12,
    00072         KEY_RETURN      = 13,
    00073         KEY_PAUSE       = 19,
    00074         KEY_ESCAPE      = 27,
    00075         KEY_SPACE       = 32,
    00076         KEY_EXCLAIM     = 33,
    00077         KEY_QUOTEDBL    = 34,
    00078         KEY_HASH        = 35,
    00079         KEY_DOLLAR      = 36,
    00080         KEY_AMPERSAND   = 38,
    00081         KEY_QUOTE       = 39,
    00082         KEY_LEFTPAREN   = 40,
    00083         KEY_RIGHTPAREN  = 41,
    00084         KEY_ASTERISK    = 42,
    00085         KEY_PLUS        = 43,
    00086         KEY_COMMA       = 44,
    00087         KEY_MINUS       = 45,
    00088         KEY_PERIOD      = 46,
    00089         KEY_SLASH       = 47,
    00090         KEY_0           = 48,
    00091         KEY_1           = 49,
    00092         KEY_2           = 50,
    00093         KEY_3           = 51,
    00094         KEY_4           = 52,
    00095         KEY_5           = 53,
    00096         KEY_6           = 54,
    00097         KEY_7           = 55,
    00098         KEY_8           = 56,
    00099         KEY_9           = 57,
    00100         KEY_COLON       = 58,
    00101         KEY_SEMICOLON   = 59,
    00102         KEY_LESS        = 60,
    00103         KEY_EQUALS      = 61,
    00104         KEY_GREATER     = 62,
    00105         KEY_QUESTION    = 63,
    00106         KEY_AT          = 64,
    00107
    00108         KEY_LEFTBRACKET = 91,
    00109         KEY_BACKSLASH   = 92,
    00110         KEY_RIGHTBRACKET= 93,
    00111         KEY_CARET       = 94,
    00112         KEY_UNDERSCORE  = 95,
    00113         KEY_BACKQUOTE   = 96,
    00114         KEY_a           = 97,
    00115         KEY_b           = 98,
    00116         KEY_c           = 99,
    00117         KEY_d           = 100,
    00118         KEY_e           = 101,
    00119         KEY_f           = 102,
    00120         KEY_g           = 103,
    00121         KEY_h           = 104,
    00122         KEY_i           = 105,
    00123         KEY_j           = 106,
    00124         KEY_k           = 107,
    00125         KEY_l           = 108,
    00126         KEY_m           = 109,
    00127         KEY_n           = 110,
    00128         KEY_o           = 111,
    00129         KEY_p           = 112,
    00130         KEY_q           = 113,
    00131         KEY_r           = 114,
    00132         KEY_s           = 115,
    00133         KEY_t           = 116,
    00134         KEY_u           = 117,
    00135         KEY_v           = 118,
    00136         KEY_w           = 119,
    00137         KEY_x           = 120,
    00138         KEY_y           = 121,
    00139         KEY_z           = 122,
    00140         KEY_DELETE      = 127,
    00141
    00142         KEY_KP0         = 256,
    00143         KEY_KP1         = 257,
    00144         KEY_KP2         = 258,
    00145         KEY_KP3         = 259,
    00146         KEY_KP4         = 260,
    00147         KEY_KP5         = 261,
    00148         KEY_KP6         = 262,
    00149         KEY_KP7         = 263,
    00150         KEY_KP8         = 264,
    00151         KEY_KP9         = 265,
    00152         KEY_KP_PERIOD   = 266,
    00153         KEY_KP_DIVIDE   = 267,
    00154         KEY_KP_MULTIPLY = 268,
    00155         KEY_KP_MINUS    = 269,
    00156         KEY_KP_PLUS     = 270,
    00157         KEY_KP_ENTER    = 271,
    00158         KEY_KP_EQUALS   = 272,
    00159
    00160         KEY_UP          = 273,
    00161         KEY_DOWN        = 274,
    00162         KEY_RIGHT       = 275,
    00163         KEY_LEFT        = 276,
    00164         KEY_INSERT      = 277,
    00165         KEY_HOME        = 278,
    00166         KEY_END         = 279,
    00167         KEY_PAGEUP      = 280,
    00168         KEY_PAGEDOWN    = 281,
    00169
    00170         KEY_F1          = 282,
    00171         KEY_F2          = 283,
    00172         KEY_F3          = 284,
    00173         KEY_F4          = 285,
    00174         KEY_F5          = 286,
    00175         KEY_F6          = 287,
    00176         KEY_F7          = 288,
    00177         KEY_F8          = 289,
    00178         KEY_F9          = 290,
    00179         KEY_F10         = 291,
    00180         KEY_F11         = 292,
    00181         KEY_F12         = 293,
    00182         KEY_F13         = 294,
    00183         KEY_F14         = 295,
    00184         KEY_F15         = 296,
    00185
    00186         KEY_NUMLOCK     = 300,
    00187         KEY_CAPSLOCK    = 301,
    00188         KEY_SCROLLOCK   = 302,
    00189         KEY_RSHIFT      = 303,
    00190         KEY_LSHIFT      = 304,
    00191         KEY_RCTRL       = 305,
    00192         KEY_LCTRL       = 306,
    00193         KEY_RALT        = 307,
    00194         KEY_LALT        = 308,
    00195         KEY_RMETA       = 309,
    00196         KEY_LMETA       = 310,
    00197         KEY_LSUPER      = 311,      /* Left "Windows" key */
    00198         KEY_RSUPER      = 312,      /* Right "Windows" key */
    00199         KEY_MODE        = 313,      /* "Alt Gr" key */
    00200         KEY_COMPOSE     = 314,      /* Multi-key compose key */
    00201
    00202         KEY_HELP        = 315,
    00203         KEY_PRINT       = 316,
    00204         KEY_SYSREQ      = 317,
    00205         KEY_BREAK       = 318,
    00206         KEY_MENU        = 319,
    00207         KEY_POWER       = 320,      /* Power Macintosh power key */
    00208         KEY_EURO        = 321,      /* Some european keyboards */
    00209         KEY_UNDO        = 322,      /* Atari keyboard has Undo */
    00210
    00211         KEY_LAST
    00212     };
    00213
    00214   protected:
    00215     int             mCode;
    00216     char            mChar;
    00217     unsigned int    mModifiers;
    00218     unsigned int    mNativeKeyCode;
    00219 };
    00220
    00221 } // namespace app
    00222 } // namespace cinder