vsg  1.1.0
VulkanSceneGraph library
KeyEvent.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/app/Window.h>
16 #include <vsg/core/observer_ptr.h>
17 #include <vsg/ui/WindowEvent.h>
18 
19 namespace vsg
20 {
21 
24  enum KeySymbol : uint16_t
25  {
26  KEY_Undefined = 0x0,
27 
28  KEY_Space = 0x20,
29 
30  KEY_0 = '0',
31  KEY_1 = '1',
32  KEY_2 = '2',
33  KEY_3 = '3',
34  KEY_4 = '4',
35  KEY_5 = '5',
36  KEY_6 = '6',
37  KEY_7 = '7',
38  KEY_8 = '8',
39  KEY_9 = '9',
40 
41  KEY_a = 'a',
42  KEY_b = 'b',
43  KEY_c = 'c',
44  KEY_d = 'd',
45  KEY_e = 'e',
46  KEY_f = 'f',
47  KEY_g = 'g',
48  KEY_h = 'h',
49  KEY_i = 'i',
50  KEY_j = 'j',
51  KEY_k = 'k',
52  KEY_l = 'l',
53  KEY_m = 'm',
54  KEY_n = 'n',
55  KEY_o = 'o',
56  KEY_p = 'p',
57  KEY_q = 'q',
58  KEY_r = 'r',
59  KEY_s = 's',
60  KEY_t = 't',
61  KEY_u = 'u',
62  KEY_v = 'v',
63  KEY_w = 'w',
64  KEY_x = 'x',
65  KEY_y = 'y',
66  KEY_z = 'z',
67 
68  KEY_A = 'A',
69  KEY_B = 'B',
70  KEY_C = 'C',
71  KEY_D = 'D',
72  KEY_E = 'E',
73  KEY_F = 'F',
74  KEY_G = 'G',
75  KEY_H = 'H',
76  KEY_I = 'I',
77  KEY_J = 'J',
78  KEY_K = 'K',
79  KEY_L = 'L',
80  KEY_M = 'M',
81  KEY_N = 'N',
82  KEY_O = 'O',
83  KEY_P = 'P',
84  KEY_Q = 'Q',
85  KEY_R = 'R',
86  KEY_S = 'S',
87  KEY_T = 'T',
88  KEY_U = 'U',
89  KEY_V = 'V',
90  KEY_W = 'W',
91  KEY_X = 'X',
92  KEY_Y = 'Y',
93  KEY_Z = 'Z',
94 
95  KEY_Exclaim = 0x21,
96  KEY_Quotedbl = 0x22,
97  KEY_Hash = 0x23,
98  KEY_Dollar = 0x24,
99  KEY_Percent = 0x25,
100  KEY_Ampersand = 0x26,
101  KEY_Quote = 0x27,
102  KEY_Leftparen = 0x28,
103  KEY_Rightparen = 0x29,
104  KEY_Asterisk = 0x2A,
105  KEY_Plus = 0x2B,
106  KEY_Comma = 0x2C,
107  KEY_Minus = 0x2D,
108  KEY_Period = 0x2E,
109  KEY_Slash = 0x2F,
110  KEY_Colon = 0x3A,
111  KEY_Semicolon = 0x3B,
112  KEY_Less = 0x3C,
113  KEY_Equals = 0x3D,
114  KEY_Greater = 0x3E,
115  KEY_Question = 0x3F,
116  KEY_At = 0x40,
117  KEY_Leftbracket = 0x5B,
118  KEY_Backslash = 0x5C,
119  KEY_Rightbracket = 0x5D,
120  KEY_Caret = 0x5E,
121  KEY_Underscore = 0x5F,
122  KEY_Backquote = 0x60,
123  KEY_Leftcurlybracket = 0x7B,
124  KEY_Verticalslash = 0x7C,
125  KEY_Rightcurlybracket = 0x7D,
126  KEY_Tilde = 0x7E,
127 
128  KEY_BackSpace = 0xFF08, /* back space, back char */
129  KEY_Tab = 0xFF09,
130  KEY_Linefeed = 0xFF0A, /* Linefeed, LF */
131  KEY_Clear = 0xFF0B,
132  KEY_Return = 0xFF0D, /* Return, enter */
133  KEY_Pause = 0xFF13, /* Pause, hold */
134  KEY_Scroll_Lock = 0xFF14,
135  KEY_Sys_Req = 0xFF15,
136  KEY_Escape = 0xFF1B,
137  KEY_Delete = 0xFFFF, /* Delete, rubout */
138 
139  /* Cursor control & motion */
140 
141  KEY_Home = 0xFF50,
142  KEY_Left = 0xFF51, /* Move left, left arrow */
143  KEY_Up = 0xFF52, /* Move up, up arrow */
144  KEY_Right = 0xFF53, /* Move right, right arrow */
145  KEY_Down = 0xFF54, /* Move down, down arrow */
146  KEY_Prior = 0xFF55, /* Prior, previous */
147  KEY_Page_Up = 0xFF55,
148  KEY_Next = 0xFF56, /* Next */
149  KEY_Page_Down = 0xFF56,
150  KEY_End = 0xFF57, /* EOL */
151  KEY_Begin = 0xFF58, /* BOL */
152 
153  /* Misc Functions */
154 
155  KEY_Select = 0xFF60, /* Select, mark */
156  KEY_Print = 0xFF61,
157  KEY_Execute = 0xFF62, /* Execute, run, do */
158  KEY_Insert = 0xFF63, /* Insert, insert here */
159  KEY_Undo = 0xFF65, /* Undo, oops */
160  KEY_Redo = 0xFF66, /* redo, again */
161  KEY_Menu = 0xFF67, /* On Windows, this is VK_APPS, the context-menu key */
162  KEY_Find = 0xFF68, /* Find, search */
163  KEY_Cancel = 0xFF69, /* Cancel, stop, abort, exit */
164  KEY_Help = 0xFF6A, /* Help */
165  KEY_Break = 0xFF6B,
166  KEY_Mode_switch = 0xFF7E, /* Character set switch */
167  KEY_Script_switch = 0xFF7E, /* Alias for mode_switch */
168  KEY_Num_Lock = 0xFF7F,
169 
170  /* Keypad Functions, keypad numbers cleverly chosen to map to ascii */
171 
172  KEY_KP_Space = 0xFF80, /* space */
173  KEY_KP_Tab = 0xFF89,
174  KEY_KP_Enter = 0xFF8D, /* enter */
175  KEY_KP_F1 = 0xFF91, /* PF1, KP_A, ... */
176  KEY_KP_F2 = 0xFF92,
177  KEY_KP_F3 = 0xFF93,
178  KEY_KP_F4 = 0xFF94,
179  KEY_KP_Home = 0xFF95,
180  KEY_KP_Left = 0xFF96,
181  KEY_KP_Up = 0xFF97,
182  KEY_KP_Right = 0xFF98,
183  KEY_KP_Down = 0xFF99,
184  KEY_KP_Prior = 0xFF9A,
185  KEY_KP_Page_Up = 0xFF9A,
186  KEY_KP_Next = 0xFF9B,
187  KEY_KP_Page_Down = 0xFF9B,
188  KEY_KP_End = 0xFF9C,
189  KEY_KP_Begin = 0xFF9D,
190  KEY_KP_Insert = 0xFF9E,
191  KEY_KP_Delete = 0xFF9F,
192  KEY_KP_Equal = 0xFFBD, /* equals */
193  KEY_KP_Multiply = 0xFFAA,
194  KEY_KP_Add = 0xFFAB,
195  KEY_KP_Separator = 0xFFAC, /* separator, often comma */
196  KEY_KP_Subtract = 0xFFAD,
197  KEY_KP_Decimal = 0xFFAE,
198  KEY_KP_Divide = 0xFFAF,
199 
200  KEY_KP_0 = 0xFFB0,
201  KEY_KP_1 = 0xFFB1,
202  KEY_KP_2 = 0xFFB2,
203  KEY_KP_3 = 0xFFB3,
204  KEY_KP_4 = 0xFFB4,
205  KEY_KP_5 = 0xFFB5,
206  KEY_KP_6 = 0xFFB6,
207  KEY_KP_7 = 0xFFB7,
208  KEY_KP_8 = 0xFFB8,
209  KEY_KP_9 = 0xFFB9,
210 
211  /*
212  * Auxiliary Functions; note the duplicate definitions for left and right
213  * function keys; Sun keyboards and a few other manufactures have such
214  * function key groups on the left and/or right sides of the keyboard.
215  * We've not found a keyboard with more than 35 function keys total.
216  */
217 
218  KEY_F1 = 0xFFBE,
219  KEY_F2 = 0xFFBF,
220  KEY_F3 = 0xFFC0,
221  KEY_F4 = 0xFFC1,
222  KEY_F5 = 0xFFC2,
223  KEY_F6 = 0xFFC3,
224  KEY_F7 = 0xFFC4,
225  KEY_F8 = 0xFFC5,
226  KEY_F9 = 0xFFC6,
227  KEY_F10 = 0xFFC7,
228  KEY_F11 = 0xFFC8,
229  KEY_F12 = 0xFFC9,
230  KEY_F13 = 0xFFCA,
231  KEY_F14 = 0xFFCB,
232  KEY_F15 = 0xFFCC,
233  KEY_F16 = 0xFFCD,
234  KEY_F17 = 0xFFCE,
235  KEY_F18 = 0xFFCF,
236  KEY_F19 = 0xFFD0,
237  KEY_F20 = 0xFFD1,
238  KEY_F21 = 0xFFD2,
239  KEY_F22 = 0xFFD3,
240  KEY_F23 = 0xFFD4,
241  KEY_F24 = 0xFFD5,
242  KEY_F25 = 0xFFD6,
243  KEY_F26 = 0xFFD7,
244  KEY_F27 = 0xFFD8,
245  KEY_F28 = 0xFFD9,
246  KEY_F29 = 0xFFDA,
247  KEY_F30 = 0xFFDB,
248  KEY_F31 = 0xFFDC,
249  KEY_F32 = 0xFFDD,
250  KEY_F33 = 0xFFDE,
251  KEY_F34 = 0xFFDF,
252  KEY_F35 = 0xFFE0,
253 
254  /* Modifiers */
255 
256  KEY_Shift_L = 0xFFE1, /* Left shift */
257  KEY_Shift_R = 0xFFE2, /* Right shift */
258  KEY_Control_L = 0xFFE3, /* Left control */
259  KEY_Control_R = 0xFFE4, /* Right control */
260  KEY_Caps_Lock = 0xFFE5, /* Caps lock */
261  KEY_Shift_Lock = 0xFFE6, /* Shift lock */
262 
263  KEY_Meta_L = 0xFFE7, /* Left meta */
264  KEY_Meta_R = 0xFFE8, /* Right meta */
265  KEY_Alt_L = 0xFFE9, /* Left alt */
266  KEY_Alt_R = 0xFFEA, /* Right alt */
267  KEY_Super_L = 0xFFEB, /* Left super */
268  KEY_Super_R = 0xFFEC, /* Right super */
269  KEY_Hyper_L = 0xFFED, /* Left hyper */
270  KEY_Hyper_R = 0xFFEE /* Right hyper */
271  };
272 
273  enum KeyModifier : uint16_t
274  {
275  MODKEY_OFF = 0,
276  MODKEY_Shift = 1,
277  MODKEY_CapsLock = 2,
278  MODKEY_Control = 4,
279  MODKEY_Alt = 8,
280  MODKEY_NumLock = 16,
281  MODKEY_Meta = 128
282  };
283 
285  class VSG_DECLSPEC KeyEvent : public Inherit<WindowEvent, KeyEvent>
286  {
287  public:
288  KeyEvent() {}
289 
290  KeyEvent(Window* in_window, time_point in_time, KeySymbol in_keyBase, KeySymbol in_keyModified, KeyModifier in_modifier, uint32_t in_repeatCount = 0) :
291  Inherit(in_window, in_time),
292  keyBase(in_keyBase),
293  keyModified(in_keyModified),
294  keyModifier(in_modifier),
295  repeatCount(in_repeatCount) {}
296 
297  KeySymbol keyBase = {};
298  KeySymbol keyModified = {};
299  KeyModifier keyModifier = {};
300  uint32_t repeatCount = 0;
301 
302  void read(Input& input) override;
303  void write(Output& output) const override;
304  };
305  VSG_type_name(vsg::KeyEvent);
306 
308  class KeyPressEvent : public Inherit<KeyEvent, KeyPressEvent>
309  {
310  public:
311  KeyPressEvent() {}
312 
313  KeyPressEvent(Window* in_window, time_point in_time, KeySymbol in_keyBase, KeySymbol in_keyModified, KeyModifier in_modifier, uint32_t in_repeatCount = 0) :
314  Inherit(in_window, in_time, in_keyBase, in_keyModified, in_modifier, in_repeatCount) {}
315  };
316  VSG_type_name(vsg::KeyPressEvent);
317 
319  class KeyReleaseEvent : public Inherit<KeyEvent, KeyReleaseEvent>
320  {
321  public:
322  KeyReleaseEvent() {}
323 
324  KeyReleaseEvent(Window* in_window, time_point in_time, KeySymbol in_keyBase, KeySymbol in_keyModified, KeyModifier in_modifier, uint32_t in_repeatCount = 0) :
325  Inherit(in_window, in_time, in_keyBase, in_keyModified, in_modifier, in_repeatCount) {}
326  };
327  VSG_type_name(vsg::KeyReleaseEvent);
328 
329 } // namespace vsg
Definition: Inherit.h:28
Definition: Input.h:44
KeyEvent is a base class for key events.
Definition: KeyEvent.h:286
KeyPressEvent represents a key press event.
Definition: KeyEvent.h:309
KeyReleaseEvent represents a key release event.
Definition: KeyEvent.h:320
Definition: Output.h:41
Definition: Window.h:31