FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
key.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_EVENTCHANNEL_KEY_H
23 #define FIFE_EVENTCHANNEL_KEY_H
24 
25 // Standard C++ library includes
26 //
27 
28 // 3rd party library includes
29 //
30 #include <SDL.h>
31 
32 // FIFE includes
33 // These includes are split up in two parts, separated by one empty line
34 // First block: files included from the FIFE root src directory
35 // Second block: files included from the same folder
36 //
37 namespace FIFE {
38 
41  class Key {
42  public:
45  enum KeyType {
46  INVALID_KEY = SDLK_UNKNOWN,
47  ENTER = SDLK_RETURN,
48  ESCAPE = SDLK_ESCAPE,
49  BACKSPACE = SDLK_BACKSPACE,
50  TAB = SDLK_TAB,
51  SPACE = SDLK_SPACE,
52  EXCLAIM = SDLK_EXCLAIM,
53  QUOTEDBL = SDLK_QUOTEDBL,
54  HASH = SDLK_HASH,
55  PERCENT = SDLK_PERCENT,
56  DOLLAR = SDLK_DOLLAR,
57  AMPERSAND = SDLK_AMPERSAND,
58  QUOTE = SDLK_QUOTE,
59  LEFTPAREN = SDLK_LEFTPAREN,
60  RIGHTPAREN = SDLK_RIGHTPAREN,
61  ASTERISK = SDLK_ASTERISK,
62  PLUS = SDLK_PLUS,
63  COMMA = SDLK_COMMA,
64  MINUS = SDLK_MINUS,
65  PERIOD = SDLK_PERIOD,
66  SLASH = SDLK_SLASH,
67  NUM_0 = SDLK_0,
68  NUM_1 = SDLK_1,
69  NUM_2 = SDLK_2,
70  NUM_3 = SDLK_3,
71  NUM_4 = SDLK_4,
72  NUM_5 = SDLK_5,
73  NUM_6 = SDLK_6,
74  NUM_7 = SDLK_7,
75  NUM_8 = SDLK_8,
76  NUM_9 = SDLK_9,
77  COLON = SDLK_COLON,
78  SEMICOLON = SDLK_SEMICOLON,
79  LESS = SDLK_LESS,
80  EQUALS = SDLK_EQUALS,
81  GREATER = SDLK_GREATER,
82  QUESTION = SDLK_QUESTION,
83  AT = SDLK_AT,
84  LEFTBRACKET = SDLK_LEFTBRACKET,
85  BACKSLASH = SDLK_BACKSLASH,
86  RIGHTBRACKET = SDLK_RIGHTBRACKET,
87  CARET = SDLK_CARET,
88  UNDERSCORE = SDLK_UNDERSCORE,
89  BACKQUOTE = SDLK_BACKQUOTE,
90  A = SDLK_a,
91  B = SDLK_b,
92  C = SDLK_c,
93  D = SDLK_d,
94  E = SDLK_e,
95  F = SDLK_f,
96  G = SDLK_g,
97  H = SDLK_h,
98  I = SDLK_i,
99  J = SDLK_j,
100  K = SDLK_k,
101  L = SDLK_l,
102  M = SDLK_m,
103  N = SDLK_n,
104  O = SDLK_o,
105  P = SDLK_p,
106  Q = SDLK_q,
107  R = SDLK_r,
108  S = SDLK_s,
109  T = SDLK_t,
110  U = SDLK_u,
111  V = SDLK_v,
112  W = SDLK_w,
113  X = SDLK_x,
114  Y = SDLK_y,
115  Z = SDLK_z,
116 
117  CAPS_LOCK = SDLK_CAPSLOCK,
118 
119  F1 = SDLK_F1,
120  F2 = SDLK_F2,
121  F3 = SDLK_F3,
122  F4 = SDLK_F4,
123  F5 = SDLK_F5,
124  F6 = SDLK_F6,
125  F7 = SDLK_F7,
126  F8 = SDLK_F8,
127  F9 = SDLK_F9,
128  F10 = SDLK_F10,
129  F11 = SDLK_F11,
130  F12 = SDLK_F12,
131 
132  PRINT_SCREEN = SDLK_PRINTSCREEN,
133  SCROLL_LOCK = SDLK_SCROLLLOCK,
134  PAUSE = SDLK_PAUSE,
135  INSERT = SDLK_INSERT,
136  HOME = SDLK_HOME,
137  PAGE_UP = SDLK_PAGEUP,
138  DELETE = SDLK_DELETE,
139  END = SDLK_END,
140  PAGE_DOWN = SDLK_PAGEDOWN,
141  RIGHT = SDLK_RIGHT,
142  LEFT = SDLK_LEFT,
143  DOWN = SDLK_DOWN,
144  UP = SDLK_UP,
145 
146  NUM_LOCK = SDLK_NUMLOCKCLEAR,
147  KP_DIVIDE = SDLK_KP_DIVIDE,
148  KP_MULTIPLY = SDLK_KP_MULTIPLY,
149  KP_MINUS = SDLK_KP_MINUS,
150  KP_PLUS = SDLK_KP_PLUS,
151  KP_ENTER = SDLK_KP_ENTER,
152  KP_0 = SDLK_KP_0,
153  KP_1 = SDLK_KP_1,
154  KP_2 = SDLK_KP_2,
155  KP_3 = SDLK_KP_3,
156  KP_4 = SDLK_KP_4,
157  KP_5 = SDLK_KP_5,
158  KP_6 = SDLK_KP_6,
159  KP_7 = SDLK_KP_7,
160  KP_8 = SDLK_KP_8,
161  KP_9 = SDLK_KP_9,
162  KP_PERIOD = SDLK_KP_PERIOD,
163 
164  APPLICATION = SDLK_APPLICATION,
165  POWER = SDLK_POWER,
166  KP_EQUALS = SDLK_KP_EQUALS,
167  F13 = SDLK_F13,
168  F14 = SDLK_F14,
169  F15 = SDLK_F15,
170  F16 = SDLK_F16,
171  F17 = SDLK_F17,
172  F18 = SDLK_F18,
173  F19 = SDLK_F19,
174  F20 = SDLK_F20,
175  F21 = SDLK_F21,
176  F22 = SDLK_F22,
177  F23 = SDLK_F23,
178  F24 = SDLK_F24,
179  EXECUTE = SDLK_EXECUTE,
180  HELP = SDLK_HELP,
181  MENU = SDLK_MENU,
182  SELECT = SDLK_SELECT,
183  STOP = SDLK_STOP,
184  AGAIN = SDLK_AGAIN,
185  UNDO = SDLK_UNDO,
186  CUT = SDLK_CUT,
187  COPY = SDLK_COPY,
188  PASTE = SDLK_PASTE,
189  FIND = SDLK_FIND,
190  MUTE = SDLK_MUTE,
191  VOLUME_UP = SDLK_VOLUMEUP,
192  VOLUME_DOWN = SDLK_VOLUMEDOWN,
193  KP_COMMA = SDLK_KP_COMMA,
194  KP_EQUALSAS400 = SDLK_KP_EQUALSAS400,
195 
196  ERASE = SDLK_ALTERASE,
197  SYS_REQ = SDLK_SYSREQ,
198  CANCEL = SDLK_CANCEL,
199  CLEAR = SDLK_CLEAR,
200  PRIOR = SDLK_PRIOR,
201  RETURN = SDLK_RETURN2,
202  SEPARATOR = SDLK_SEPARATOR,
203  FORTH = SDLK_OUT,
204  OPER = SDLK_OPER,
205  CLEAR_AGAIN = SDLK_CLEARAGAIN,
206  CR_SEL = SDLK_CRSEL,
207  EX_SEL = SDLK_EXSEL,
208 
209  KP_00 = SDLK_KP_00,
210  KP_000 = SDLK_KP_000,
211  THOUSANDS_SEPARATOR = SDLK_THOUSANDSSEPARATOR,
212  DECIMAL_SEPARATOR = SDLK_DECIMALSEPARATOR,
213  CURRENCY_UNIT = SDLK_CURRENCYUNIT,
214  CURRENCY_SUBUNIT = SDLK_CURRENCYSUBUNIT,
215  KP_LEFTPAREN = SDLK_KP_LEFTPAREN,
216  KP_RIGHTPAREN = SDLK_KP_RIGHTPAREN,
217  KP_LEFTBRACE = SDLK_KP_LEFTBRACE,
218  KP_RIGHTBRACE = SDLK_KP_RIGHTBRACE,
219  KP_TAB = SDLK_KP_TAB,
220  KP_BACKSPACE = SDLK_KP_BACKSPACE,
221  KP_A = SDLK_KP_A,
222  KP_B = SDLK_KP_B,
223  KP_C = SDLK_KP_C,
224  KP_D = SDLK_KP_D,
225  KP_E = SDLK_KP_E,
226  KP_F = SDLK_KP_F,
227  KP_XOR = SDLK_KP_XOR,
228  KP_POWER = SDLK_KP_POWER,
229  KP_PERCENT = SDLK_KP_PERCENT,
230  KP_LESS = SDLK_KP_LESS,
231  KP_GREATER = SDLK_KP_GREATER,
232  KP_AMPERSAND = SDLK_KP_AMPERSAND,
233  KP_DBLAMPERSAND = SDLK_KP_DBLAMPERSAND,
234  KP_VERTICALBAR = SDLK_KP_VERTICALBAR,
235  KP_DBLVERTICALBAR = SDLK_KP_DBLVERTICALBAR,
236  KP_COLON = SDLK_KP_COLON,
237  KP_HASH = SDLK_KP_HASH,
238  KP_SPACE = SDLK_KP_SPACE,
239  KP_AT = SDLK_KP_AT,
240  KP_EXCLAM = SDLK_KP_EXCLAM,
241  KP_MEMSTORE = SDLK_KP_MEMSTORE,
242  KP_MEMRECALL = SDLK_KP_MEMRECALL,
243  KP_MEMCLEAR = SDLK_KP_MEMCLEAR,
244  KP_MEMADD = SDLK_KP_MEMADD,
245  KP_MEMSUBSTRACT = SDLK_KP_MEMSUBTRACT,
246  KP_MEMMULTIPLY = SDLK_KP_MEMMULTIPLY,
247  KP_MEMDIVIDE = SDLK_KP_MEMDIVIDE,
248  KP_PLUSMINUS = SDLK_KP_PLUSMINUS,
249  KP_CLEAR = SDLK_KP_CLEAR,
250  KP_CLEARENTRY = SDLK_KP_CLEARENTRY,
251  KP_BINARY = SDLK_KP_BINARY,
252  KP_OCTAL = SDLK_KP_OCTAL,
253  KP_DECIMAL = SDLK_KP_DECIMAL,
254  KP_HEXADECIMAL = SDLK_KP_HEXADECIMAL,
255 
256  LEFT_CONTROL = SDLK_LCTRL,
257  LEFT_SHIFT = SDLK_LSHIFT,
258  LEFT_ALT = SDLK_LALT,
259  LEFT_SUPER = SDLK_LGUI,
260  RIGHT_CONTROL = SDLK_RCTRL,
261  RIGHT_SHIFT = SDLK_RSHIFT,
262  RIGHT_ALT = SDLK_RALT,
263  RIGHT_SUPER = SDLK_RGUI,
264 
265  ALT_GR = SDLK_MODE,
266 
267  AUDIO_NEXT = SDLK_AUDIONEXT,
268  AUDIO_PREV = SDLK_AUDIOPREV,
269  AUDIO_STOP = SDLK_AUDIOSTOP,
270  AUDIO_PLAY = SDLK_AUDIOPLAY,
271  AUDIO_MUTE = SDLK_AUDIOMUTE,
272  MEDIASELECT = SDLK_MEDIASELECT,
273  WWW = SDLK_WWW,
274  MAIL = SDLK_MAIL,
275  CALCULATOR = SDLK_CALCULATOR,
276  COMPUTER = SDLK_COMPUTER,
277  AC_SEARCH = SDLK_AC_SEARCH,
278  AC_HOME = SDLK_AC_HOME,
279  AC_BACK = SDLK_AC_BACK,
280  AC_FORWARD = SDLK_AC_FORWARD,
281  AC_STOP = SDLK_AC_STOP,
282  AC_REFRESH = SDLK_AC_REFRESH,
283  AC_BOOKMARKS = SDLK_AC_BOOKMARKS,
284 
285  BRIGHTNESS_DOWN = SDLK_BRIGHTNESSDOWN,
286  BRIGHTNESS_UP = SDLK_BRIGHTNESSUP,
287  DISPLAY_SWITCH = SDLK_DISPLAYSWITCH,
288  ILLUM_TOGGLE = SDLK_KBDILLUMTOGGLE,
289  ILLUM_DOWN = SDLK_KBDILLUMDOWN,
290  ILLUM_UP = SDLK_KBDILLUMUP,
291  EJECT = SDLK_EJECT,
292  SLEEP = SDLK_SLEEP
293  };
298  m_key(key) {}
299 
302  virtual ~Key() {}
303 
306  bool isPrintable() const {
307  std::string name = getAsString();
308  if (!name.empty()) {
309  return true;
310  }
311  return false;
312  }
313 
314  bool isFunctionKey() const {
315  // ToDo
316  return (m_key >= F1 && m_key <= F12) || (m_key >= F13 && m_key <= F24);
317  }
318 
321  KeyType getValue() const {
322  return m_key;
323  }
324 
327  std::string getAsString() const {
328  std::string name(SDL_GetKeyName(static_cast<SDL_Keycode>(m_key)));
329  return name;
330  }
331 
332  private:
334  };
335 
336 } //FIFE
337 
338 #endif
KeyType
Codes for different keys.
Definition: key.h:45
KeyType getValue() const
Gets the value of the key.
Definition: key.h:321
KeyType m_key
Definition: key.h:333
bool isPrintable() const
Tells whether the Key can be represented as a string.
Definition: key.h:306
std::string getAsString() const
Gets the string representation of the key, encoded as UTF-8.
Definition: key.h:327
Represents a key.
Definition: key.h:41
bool isFunctionKey() const
Definition: key.h:314
Key(KeyType key=INVALID_KEY)
Constructor.
Definition: key.h:297
virtual ~Key()
Destructor.
Definition: key.h:302