1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
11 * Scritch Input Library.
16 #ifndef SQUIRRELJME_SCRITCHINPUT_H
17 #define SQUIRRELJME_SCRITCHINPUT_H
19 #include "sjme/stdTypes.h"
23 #ifndef SJME_CXX_IS_EXTERNED
24 #define SJME_CXX_IS_EXTERNED
25 #define SJME_CXX_SQUIRRELJME_SCRITCHINPUT_H
27 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
28 #endif /* #ifdef __cplusplus */
30 /*--------------------------------------------------------------------------*/
33 * The types of events that are possible.
37 typedef enum sjme_scritchinput_type
40 SJME_SCRITCHINPUT_TYPE_UNKNOWN
= 0,
42 /** Key event: Pressed. */
43 SJME_SCRITCHINPUT_TYPE_KEY_PRESSED
= 1,
45 /** Key event: Released. */
46 SJME_SCRITCHINPUT_TYPE_KEY_RELEASED
= 2,
48 /** Key event: Repeated. */
49 SJME_SCRITCHINPUT_TYPE_KEY_REPEATED
= 4,
51 /** Mouse event: Button pressed. */
52 SJME_SCRITCHINPUT_TYPE_MOUSE_BUTTON_PRESSED
= 8,
54 /** Mouse event: Button released. */
55 SJME_SCRITCHINPUT_TYPE_MOUSE_BUTTON_RELEASED
= 16,
57 /** Mouse event: Motion. */
58 SJME_SCRITCHINPUT_TYPE_MOUSE_MOTION
= 32,
60 /** Gamepad event: Button pressed. */
61 SJME_SCRITCHINPUT_TYPE_GAMEPAD_BUTTON_PRESSED
= 64,
63 /** Gamepad event: Button released. */
64 SJME_SCRITCHINPUT_TYPE_GAMEPAD_BUTTON_RELEASED
= 128,
66 /** Gamepad event: Motion on axis. */
67 SJME_SCRITCHINPUT_TYPE_GAMEPAD_AXIS_MOTION
= 256,
69 /** Touch event: Finger pressed. */
70 SJME_SCRITCHINPUT_TYPE_TOUCH_FINGER_PRESSED
= 512,
72 /** Touch event: Finger released. */
73 SJME_SCRITCHINPUT_TYPE_TOUCH_FINGER_RELEASED
= 1024,
75 /** Touch event: Drag motion. */
76 SJME_SCRITCHINPUT_TYPE_TOUCH_DRAG_MOTION
= 2048,
78 /** Stylus event: Pressed. */
79 SJME_SCRITCHINPUT_TYPE_STYLUS_PEN_PRESSED
= 4096,
81 /** Stylus event: Released. */
82 SJME_SCRITCHINPUT_TYPE_STYLUS_PEN_RELEASED
= 8192,
84 /** Stylus event: Dragging motion. */
85 SJME_SCRITCHINPUT_TYPE_STYLUS_DRAG_MOTION
= 16384,
87 /** Stylus event: Hovering over display. */
88 SJME_SCRITCHINPUT_TYPE_STYLUS_HOVER_MOTION
= 32768,
90 /** Gyroscope event: Axis motion. */
91 SJME_SCRITCHINPUT_TYPE_GYRO_AXIS_MOTION
= 65536,
93 /** Device action (flip open/close, shaken, not stirred). */
94 SJME_SCRITCHINPUT_TYPE_DEVICE_ACTION
= 131072,
96 /** A character key was pressed. */
97 SJME_SCRITCHINPUT_TYPE_KEY_CHAR_PRESSED
= 262144,
98 } sjme_scritchinput_type
;
100 typedef enum sjme_scritchinput_key
103 SJME_SCRITCHINPUT_KEY_BACKSPACE
= 8,
106 SJME_SCRITCHINPUT_KEY_TAB
= 9,
109 SJME_SCRITCHINPUT_KEY_ENTER
= 10,
112 SJME_SCRITCHINPUT_KEY_ESCAPE
= 27,
115 SJME_SCRITCHINPUT_KEY_STAR
= 42,
118 SJME_SCRITCHINPUT_KEY_SPACE
= 32,
121 SJME_SCRITCHINPUT_KEY_POUND
= 35,
124 SJME_SCRITCHINPUT_KEY_DELETE
= 127,
126 /** Unknown, zero is the invalid index so always make it known. */
127 SJME_SCRITCHINPUT_KEY_UNKNOWN
= 0,
129 /** The up arrow key. */
130 SJME_SCRITCHINPUT_KEY_UP
= -1,
132 /** Down arrow key. */
133 SJME_SCRITCHINPUT_KEY_DOWN
= -2,
135 /** Left arrow key. */
136 SJME_SCRITCHINPUT_KEY_LEFT
= -3,
138 /** Right arrow key. */
139 SJME_SCRITCHINPUT_KEY_RIGHT
= -4,
142 SJME_SCRITCHINPUT_KEY_VGAME_UP
= -9,
145 SJME_SCRITCHINPUT_KEY_VGAME_DOWN
= -10,
148 SJME_SCRITCHINPUT_KEY_VGAME_LEFT
= -11,
151 SJME_SCRITCHINPUT_KEY_VGAME_RIGHT
= -12,
154 SJME_SCRITCHINPUT_KEY_VGAME_FIRE
= -13,
157 SJME_SCRITCHINPUT_KEY_VGAME_A
= -14,
160 SJME_SCRITCHINPUT_KEY_VGAME_B
= -15,
163 SJME_SCRITCHINPUT_KEY_VGAME_C
= -16,
166 SJME_SCRITCHINPUT_KEY_VGAME_D
= -17,
169 SJME_SCRITCHINPUT_KEY_SHIFT
= -18,
172 SJME_SCRITCHINPUT_KEY_CONTROL
= -19,
175 SJME_SCRITCHINPUT_KEY_ALT
= -20,
178 SJME_SCRITCHINPUT_KEY_LOGO
= -21,
181 SJME_SCRITCHINPUT_KEY_CAPSLOCK
= -22,
184 SJME_SCRITCHINPUT_KEY_CONTEXT_MENU
= -23,
187 SJME_SCRITCHINPUT_KEY_HOME
= -24,
190 SJME_SCRITCHINPUT_KEY_END
= -25,
193 SJME_SCRITCHINPUT_KEY_PAGE_UP
= -26,
196 SJME_SCRITCHINPUT_KEY_PAGE_DOWN
= -27,
199 SJME_SCRITCHINPUT_KEY_META
= -28,
202 SJME_SCRITCHINPUT_KEY_NUMLOCK
= -29,
205 SJME_SCRITCHINPUT_KEY_PAUSE
= -30,
208 SJME_SCRITCHINPUT_KEY_PRINTSCREEN
= -31,
211 SJME_SCRITCHINPUT_KEY_SCROLLLOCK
= -32,
214 SJME_SCRITCHINPUT_KEY_INSERT
= -33,
216 /** Game Virtual Left Command. */
217 SJME_SCRITCHINPUT_KEY_VGAME_COMMAND_LEFT
= -34,
219 /** Game Virtual Right Command. */
220 SJME_SCRITCHINPUT_KEY_VGAME_COMMAND_RIGHT
= -35,
222 /** Game virtual Center Command. */
223 SJME_SCRITCHINPUT_KEY_VGAME_COMMAND_CENTER
= -36,
225 /** Game virtual open LCDUI inspector. */
226 SJME_SCRITCHINPUT_KEY_VGAME_LCDUI_INSPECTOR
= -37,
228 /** Number pad divide. */
229 SJME_SCRITCHINPUT_KEY_NUMPAD_DIVIDE
= -38,
231 /** Number pad multiply. */
232 SJME_SCRITCHINPUT_KEY_NUMPAD_MULTIPLY
= -39,
234 /** Number pad minus. */
235 SJME_SCRITCHINPUT_KEY_NUMPAD_MINUS
= -40,
237 /** Number pad plus. */
238 SJME_SCRITCHINPUT_KEY_NUMPAD_PLUS
= -41,
240 /** Number pad decimal. */
241 SJME_SCRITCHINPUT_KEY_NUMPAD_DECIMAL
= -42,
243 /** Number pad enter. */
244 SJME_SCRITCHINPUT_KEY_NUMPAD_ENTER
= -43,
247 SJME_SCRITCHINPUT_KEY_NUMPAD_0
= -50,
250 SJME_SCRITCHINPUT_KEY_NUMPAD_1
= -51,
253 SJME_SCRITCHINPUT_KEY_NUMPAD_2
= -52,
256 SJME_SCRITCHINPUT_KEY_NUMPAD_3
= -53,
259 SJME_SCRITCHINPUT_KEY_NUMPAD_4
= -54,
262 SJME_SCRITCHINPUT_KEY_NUMPAD_5
= -55,
265 SJME_SCRITCHINPUT_KEY_NUMPAD_6
= -56,
268 SJME_SCRITCHINPUT_KEY_NUMPAD_7
= -57,
271 SJME_SCRITCHINPUT_KEY_NUMPAD_8
= -58,
274 SJME_SCRITCHINPUT_KEY_NUMPAD_9
= -59,
277 SJME_SCRITCHINPUT_KEY_F24
= -64,
280 SJME_SCRITCHINPUT_KEY_F23
= -65,
283 SJME_SCRITCHINPUT_KEY_F22
= -66,
286 SJME_SCRITCHINPUT_KEY_F21
= -67,
289 SJME_SCRITCHINPUT_KEY_F20
= -68,
292 SJME_SCRITCHINPUT_KEY_F19
= -69,
295 SJME_SCRITCHINPUT_KEY_F18
= -70,
298 SJME_SCRITCHINPUT_KEY_F17
= -71,
301 SJME_SCRITCHINPUT_KEY_F16
= -72,
304 SJME_SCRITCHINPUT_KEY_F15
= -73,
307 SJME_SCRITCHINPUT_KEY_F14
= -74,
310 SJME_SCRITCHINPUT_KEY_F13
= -75,
313 SJME_SCRITCHINPUT_KEY_F12
= -76,
316 SJME_SCRITCHINPUT_KEY_F11
= -77,
319 SJME_SCRITCHINPUT_KEY_F10
= -78,
322 SJME_SCRITCHINPUT_KEY_F9
= -79,
325 SJME_SCRITCHINPUT_KEY_F8
= -80,
328 SJME_SCRITCHINPUT_KEY_F7
= -81,
331 SJME_SCRITCHINPUT_KEY_F6
= -82,
334 SJME_SCRITCHINPUT_KEY_F5
= -83,
337 SJME_SCRITCHINPUT_KEY_F4
= -84,
340 SJME_SCRITCHINPUT_KEY_F3
= -85,
343 SJME_SCRITCHINPUT_KEY_F2
= -86,
346 SJME_SCRITCHINPUT_KEY_F1
= -87,
347 } sjme_scritchinput_key
;
349 typedef enum sjme_scritchinput_modifier
351 /** Modifier status not supported. */
352 SJME_SCRITCHINPUT_MODIFIER_UNSUPPORTED
= -1,
354 /** Alt key modifier. */
355 SJME_SCRITCHINPUT_MODIFIER_ALT
= 65536,
357 /** Function (Fn/Chr) key modifier. */
358 SJME_SCRITCHINPUT_MODIFIER_CHR
= 8388608,
360 /** Command key modifier. */
361 SJME_SCRITCHINPUT_MODIFIER_COMMAND
= 4194304,
363 /** Ctrl key modifier. */
364 SJME_SCRITCHINPUT_MODIFIER_CTRL
= 262144,
366 /** Shift key modifier. */
367 SJME_SCRITCHINPUT_MODIFIER_SHIFT
= 131072,
369 /** Mask for all the modifier keys. */
370 SJME_SCRITCHINPUT_MODIFIER_MASK
= 13041664,
371 } sjme_scritchinput_modifier
;
373 typedef struct sjme_scritchinput_eventDataUnknown
410 } sjme_scritchinput_eventDataUnknown
;
413 * Event data for key events.
417 typedef struct sjme_scritchinput_eventDataKey
419 /** Unicode key core or @c sjme_scritchinput_key . */
422 /** The modifiers held down, from @c sjme_scritchinput_modifier . */
424 } sjme_scritchinput_eventDataKey
;
426 typedef struct sjme_scritchinput_eventDataMouseButton
428 /** The buttons being pressed. */
429 sjme_jint buttonMask
;
431 /** The modifiers held down, from @c sjme_scritchinput_modifier . */
434 /** The X coordinate. */
437 /** The Y coordinate. */
440 /** The button being pressed. */
442 } sjme_scritchinput_eventDataMouseButton
;
444 typedef struct sjme_scritchinput_eventDataMouseMotion
446 /** The buttons being pressed. */
447 sjme_jint buttonMask
;
449 /** The modifiers held down, from @c sjme_scritchinput_modifier . */
452 /** The X coordinate. */
455 /** The Y coordinate. */
457 } sjme_scritchinput_eventDataMouseMotion
;
459 typedef struct sjme_scritchinput_eventDataGamePadButton
462 } sjme_scritchinput_eventDataGamePadButton
;
464 typedef struct sjme_scritchinput_eventDataGamePadAxisMotion
467 } sjme_scritchinput_eventDataGamePadAxisMotion
;
469 typedef struct sjme_scritchinput_eventDataTouchFinger
472 } sjme_scritchinput_eventDataTouchFinger
;
474 typedef struct sjme_scritchinput_eventDataTouchDrag
477 } sjme_scritchinput_eventDataTouchDrag
;
479 typedef struct sjme_scritchinput_eventDataStylusPen
482 } sjme_scritchinput_eventDataStylusPen
;
484 typedef struct sjme_scritchinput_eventDataStylusMotion
487 } sjme_scritchinput_eventDataStylusMotion
;
489 typedef struct sjme_scritchinput_eventDataDeviceAction
492 } sjme_scritchinput_eventDataDeviceAction
;
495 * Structure which contains event data and otherwise.
499 typedef struct sjme_scritchinput_event
501 /** The type of event that has occurred. */
502 sjme_scritchinput_type type
;
504 /** The time the event occurred at. */
507 /** The event data. */
510 /** Unknown event. */
511 sjme_scritchinput_eventDataUnknown unknown
;
514 sjme_scritchinput_eventDataKey key
;
516 /** Mouse button events. */
517 sjme_scritchinput_eventDataMouseButton mouseButton
;
519 /** Mouse motion events. */
520 sjme_scritchinput_eventDataMouseMotion mouseMotion
;
522 /** Game pad button. */
523 sjme_scritchinput_eventDataGamePadButton gamePadButton
;
525 /** Game pad axis motion. */
526 sjme_scritchinput_eventDataGamePadAxisMotion gamePadAxisMotion
;
528 /** Touchscreen/Touchpad finger. */
529 sjme_scritchinput_eventDataTouchFinger touchFinger
;
532 sjme_scritchinput_eventDataTouchDrag touchDrag
;
535 sjme_scritchinput_eventDataStylusPen stylusPen
;
537 /** Stylus motion. */
538 sjme_scritchinput_eventDataStylusMotion stylusMotion
;
540 /** Device action. */
541 sjme_scritchinput_eventDataDeviceAction deviceAction
;
543 } sjme_scritchinput_event
;
545 /*--------------------------------------------------------------------------*/
549 #ifdef SJME_CXX_SQUIRRELJME_SCRITCHINPUT_H
551 #undef SJME_CXX_SQUIRRELJME_SCRITCHINPUT_H
552 #undef SJME_CXX_IS_EXTERNED
553 #endif /* #ifdef SJME_CXX_SQUIRRELJME_SCRITCHINPUT_H */
554 #endif /* #ifdef __cplusplus */
556 #endif /* SQUIRRELJME_SCRITCHINPUT_H */