Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KeyEvent.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, The Cinder Project, All rights reserved.
3 
4  This code is intended for use with the Cinder C++ library: http://libcinder.org
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7  the following conditions are met:
8 
9  * Redistributions of source code must retain the above copyright notice, this list of conditions and
10  the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12  the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21  POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 #pragma once
25 
26 #include "cinder/Cinder.h"
27 #include "cinder/app/Event.h"
28 
29 namespace cinder{ namespace app{
30 
32 class KeyEvent : public Event {
33  public:
35  {}
36  KeyEvent( WindowRef win, int aCode, uint32_t aChar32, char aChar, unsigned int aModifiers, unsigned int aNativeKeyCode )
37  : Event( win ), mCode( aCode ), mChar32( aChar32 ), mChar( aChar ), mModifiers( aModifiers ), mNativeKeyCode( aNativeKeyCode )
38  {}
39 
41  char getChar() const { return mChar; }
43  uint32_t getCharUtf32() const { return mChar32; }
45  int getCode() const { return mCode; }
47  bool isShiftDown() const { return (mModifiers & SHIFT_DOWN) ? true : false; }
49  bool isAltDown() const { return (mModifiers & ALT_DOWN) ? true : false; }
51  bool isControlDown() const { return (mModifiers & CTRL_DOWN) ? true : false; }
53  bool isMetaDown() const { return (mModifiers & META_DOWN) ? true : false; }
55  bool isAccelDown() const { return (mModifiers & ACCEL_DOWN) ? true : false; }
57  int getNativeKeyCode() const { return mNativeKeyCode; }
58 
59 #if ! defined( CINDER_COCOA_TOUCH )
60  static int translateNativeKeyCode( int nativeKeyCode );
62 #endif
63 
64  enum { SHIFT_DOWN = 0x0008,
65  ALT_DOWN = 0x0010,
66  CTRL_DOWN = 0x0020,
67  META_DOWN = 0x0040,
68 #if (defined( CINDER_MSW ) || defined( CINDER_WINRT ))
70 #else
72 #endif
73  };
74 
75  // Key codes
76  enum {
78  KEY_FIRST = 0,
80  KEY_TAB = 9,
81  KEY_CLEAR = 12,
82  KEY_RETURN = 13,
83  KEY_PAUSE = 19,
84  KEY_ESCAPE = 27,
85  KEY_SPACE = 32,
88  KEY_HASH = 35,
89  KEY_DOLLAR = 36,
91  KEY_QUOTE = 39,
95  KEY_PLUS = 43,
96  KEY_COMMA = 44,
97  KEY_MINUS = 45,
98  KEY_PERIOD = 46,
99  KEY_SLASH = 47,
100  KEY_0 = 48,
101  KEY_1 = 49,
102  KEY_2 = 50,
103  KEY_3 = 51,
104  KEY_4 = 52,
105  KEY_5 = 53,
106  KEY_6 = 54,
107  KEY_7 = 55,
108  KEY_8 = 56,
109  KEY_9 = 57,
110  KEY_COLON = 58,
112  KEY_LESS = 60,
116  KEY_AT = 64,
117 
121  KEY_CARET = 94,
124  KEY_a = 97,
125  KEY_b = 98,
126  KEY_c = 99,
127  KEY_d = 100,
128  KEY_e = 101,
129  KEY_f = 102,
130  KEY_g = 103,
131  KEY_h = 104,
132  KEY_i = 105,
133  KEY_j = 106,
134  KEY_k = 107,
135  KEY_l = 108,
136  KEY_m = 109,
137  KEY_n = 110,
138  KEY_o = 111,
139  KEY_p = 112,
140  KEY_q = 113,
141  KEY_r = 114,
142  KEY_s = 115,
143  KEY_t = 116,
144  KEY_u = 117,
145  KEY_v = 118,
146  KEY_w = 119,
147  KEY_x = 120,
148  KEY_y = 121,
149  KEY_z = 122,
150  KEY_DELETE = 127,
151 
152  KEY_KP0 = 256,
153  KEY_KP1 = 257,
154  KEY_KP2 = 258,
155  KEY_KP3 = 259,
156  KEY_KP4 = 260,
157  KEY_KP5 = 261,
158  KEY_KP6 = 262,
159  KEY_KP7 = 263,
160  KEY_KP8 = 264,
161  KEY_KP9 = 265,
166  KEY_KP_PLUS = 270,
169 
170  KEY_UP = 273,
171  KEY_DOWN = 274,
172  KEY_RIGHT = 275,
173  KEY_LEFT = 276,
174  KEY_INSERT = 277,
175  KEY_HOME = 278,
176  KEY_END = 279,
177  KEY_PAGEUP = 280,
179 
180  KEY_F1 = 282,
181  KEY_F2 = 283,
182  KEY_F3 = 284,
183  KEY_F4 = 285,
184  KEY_F5 = 286,
185  KEY_F6 = 287,
186  KEY_F7 = 288,
187  KEY_F8 = 289,
188  KEY_F9 = 290,
189  KEY_F10 = 291,
190  KEY_F11 = 292,
191  KEY_F12 = 293,
192  KEY_F13 = 294,
193  KEY_F14 = 295,
194  KEY_F15 = 296,
195 
196  KEY_NUMLOCK = 300,
199  KEY_RSHIFT = 303,
200  KEY_LSHIFT = 304,
201  KEY_RCTRL = 305,
202  KEY_LCTRL = 306,
203  KEY_RALT = 307,
204  KEY_LALT = 308,
205  KEY_RMETA = 309,
206  KEY_LMETA = 310,
207  KEY_LSUPER = 311, /* Left "Windows" key */
208  KEY_RSUPER = 312, /* Right "Windows" key */
209  KEY_MODE = 313, /* "Alt Gr" key */
210  KEY_COMPOSE = 314, /* Multi-key compose key */
211 
212  KEY_HELP = 315,
213  KEY_PRINT = 316,
214  KEY_SYSREQ = 317,
215  KEY_BREAK = 318,
216  KEY_MENU = 319,
217  KEY_POWER = 320, /* Power Macintosh power key */
218  KEY_EURO = 321, /* Some european keyboards */
219  KEY_UNDO = 322, /* Atari keyboard has Undo */
220 
222  };
223 
224  protected:
225  int mCode;
226  uint32_t mChar32;
227  char mChar;
228  unsigned int mModifiers;
229  unsigned int mNativeKeyCode;
231 };
232 
233 } } // namespace cinder::app
Definition: KeyEvent.h:180
Definition: KeyEvent.h:99
Definition: KeyEvent.h:135
Definition: KeyEvent.h:118
Definition: KeyEvent.h:109
Definition: KeyEvent.h:65
Definition: KeyEvent.h:203
Definition: KeyEvent.h:183
Definition: KeyEvent.h:124
Definition: KeyEvent.h:64
Definition: KeyEvent.h:215
Definition: KeyEvent.h:185
Definition: KeyEvent.h:144
Definition: KeyEvent.h:131
Definition: KeyEvent.h:213
Definition: KeyEvent.h:154
Definition: KeyEvent.h:205
Definition: KeyEvent.h:85
Definition: KeyEvent.h:198
Definition: KeyEvent.h:110
Definition: KeyEvent.h:187
Definition: KeyEvent.h:71
KeyEvent(WindowRef win, int aCode, uint32_t aChar32, char aChar, unsigned int aModifiers, unsigned int aNativeKeyCode)
Definition: KeyEvent.h:36
int getCode() const
Returns the key code associated with the event, which maps into the enum listed below.
Definition: KeyEvent.h:45
Definition: KeyEvent.h:209
Definition: KeyEvent.h:212
Definition: KeyEvent.h:161
Definition: KeyEvent.h:138
unsigned int mNativeKeyCode
Definition: KeyEvent.h:229
Definition: KeyEvent.h:133
Definition: KeyEvent.h:88
Definition: KeyEvent.h:204
Definition: KeyEvent.h:82
Definition: KeyEvent.h:152
Definition: KeyEvent.h:97
Definition: KeyEvent.h:221
Definition: KeyEvent.h:200
Definition: KeyEvent.h:150
Definition: KeyEvent.h:170
Definition: KeyEvent.h:116
Definition: KeyEvent.h:93
Definition: KeyEvent.h:119
uint32_t mChar32
Definition: KeyEvent.h:226
Definition: KeyEvent.h:168
char getChar() const
Returns the ASCII character associated with the event.
Definition: KeyEvent.h:41
Definition: KeyEvent.h:100
Definition: KeyEvent.h:79
Definition: KeyEvent.h:130
GLXFBConfig Window win
Definition: GLee.h:16730
Definition: KeyEvent.h:177
Definition: KeyEvent.h:111
Definition: KeyEvent.h:134
bool isAccelDown() const
Returns whether the accelerator key was pressed during the event. Maps to the Control key on Windows ...
Definition: KeyEvent.h:55
Definition: KeyEvent.h:219
bool isShiftDown() const
Returns whether the Shift key was pressed during the event.
Definition: KeyEvent.h:47
Definition: KeyEvent.h:197
Definition: KeyEvent.h:188
Definition: KeyEvent.h:175
Definition: KeyEvent.h:114
Definition: KeyEvent.h:147
Definition: KeyEvent.h:101
Definition: KeyEvent.h:155
Definition: KeyEvent.h:159
Definition: KeyEvent.h:115
Definition: KeyEvent.h:171
Definition: KeyEvent.h:66
std::shared_ptr< Window > WindowRef
Definition: Event.h:49
Definition: KeyEvent.h:201
Definition: KeyEvent.h:218
bool isMetaDown() const
Returns whether the meta key was pressed during the event. Maps to the Windows key on Windows and the...
Definition: KeyEvent.h:53
Definition: KeyEvent.h:103
Definition: KeyEvent.h:167
Definition: KeyEvent.h:202
Definition: KeyEvent.h:89
Definition: KeyEvent.h:136
Definition: KeyEvent.h:84
Definition: KeyEvent.h:164
Definition: KeyEvent.h:102
Definition: KeyEvent.h:174
Definition: KeyEvent.h:139
Definition: KeyEvent.h:160
KeyEvent()
Definition: KeyEvent.h:34
Definition: KeyEvent.h:191
Definition: KeyEvent.h:95
Definition: KeyEvent.h:186
unsigned int mModifiers
Definition: KeyEvent.h:228
Definition: KeyEvent.h:165
Definition: KeyEvent.h:67
Definition: KeyEvent.h:178
Definition: KeyEvent.h:181
static int translateNativeKeyCode(int nativeKeyCode)
Maps a platform-native key-code to the key code enum.
Definition: KeyEvent.h:194
uint32_t getCharUtf32() const
Returns the UTF-32 character associated with the event.
Definition: KeyEvent.h:43
Definition: KeyEvent.h:166
Base class for all Events.
Definition: Event.h:53
Definition: KeyEvent.h:145
Definition: KeyEvent.h:193
Definition: KeyEvent.h:163
Definition: KeyEvent.h:199
Definition: KeyEvent.h:92
Definition: KeyEvent.h:140
bool isAltDown() const
Returns whether the Alt (or Option) key was pressed during the event.
Definition: KeyEvent.h:49
Definition: KeyEvent.h:125
Definition: KeyEvent.h:106
Definition: KeyEvent.h:77
Definition: KeyEvent.h:149
Definition: KeyEvent.h:143
Definition: KeyEvent.h:91
int getNativeKeyCode() const
Returns the platform-native key-code. Advanced users only.
Definition: KeyEvent.h:57
Definition: KeyEvent.h:108
Definition: KeyEvent.h:129
Definition: KeyEvent.h:196
Definition: KeyEvent.h:90
Definition: KeyEvent.h:120
Definition: KeyEvent.h:128
Definition: KeyEvent.h:142
Definition: KeyEvent.h:158
Definition: KeyEvent.h:137
Definition: KeyEvent.h:127
Definition: KeyEvent.h:216
Definition: KeyEvent.h:210
Definition: KeyEvent.h:122
Definition: KeyEvent.h:182
Definition: KeyEvent.h:80
Definition: KeyEvent.h:141
Definition: KeyEvent.h:123
Definition: KeyEvent.h:132
Definition: KeyEvent.h:156
Definition: KeyEvent.h:105
Definition: KeyEvent.h:148
Definition: KeyEvent.h:78
int mCode
Definition: KeyEvent.h:225
Definition: KeyEvent.h:153
Definition: KeyEvent.h:206
Definition: KeyEvent.h:162
bool isControlDown() const
Returns whether the Control key was pressed during the event.
Definition: KeyEvent.h:51
WindowRef mWindow
Definition: KeyEvent.h:230
Definition: KeyEvent.h:96
Definition: KeyEvent.h:81
Definition: KeyEvent.h:113
Definition: KeyEvent.h:98
char mChar
Definition: KeyEvent.h:227
Definition: KeyEvent.h:94
Definition: KeyEvent.h:214
Definition: KeyEvent.h:121
Definition: KeyEvent.h:190
Definition: KeyEvent.h:207
Definition: KeyEvent.h:104
Definition: KeyEvent.h:157
Definition: KeyEvent.h:172
Definition: KeyEvent.h:87
Definition: KeyEvent.h:146
Definition: KeyEvent.h:86
Definition: KeyEvent.h:173
Definition: KeyEvent.h:112
Represents a keyboard event.
Definition: KeyEvent.h:32
Definition: KeyEvent.h:107
Definition: KeyEvent.h:189
Definition: KeyEvent.h:83
Definition: KeyEvent.h:176
Definition: KeyEvent.h:184
Definition: KeyEvent.h:217
Definition: KeyEvent.h:126
Definition: KeyEvent.h:192
Definition: KeyEvent.h:208