pyxel_platform/
keys.rs

1use paste::paste;
2
3use crate::sdl2_sys::*;
4
5pub type Key = u32;
6pub type KeyValue = i32;
7
8// Keyboard (based on SDL_keycode.h in SDL 2.0.10)
9pub const KEY_UNKNOWN: Key = SDLK_UNKNOWN as Key;
10pub const KEY_RETURN: Key = SDLK_RETURN as Key;
11pub const KEY_ESCAPE: Key = SDLK_ESCAPE as Key;
12pub const KEY_BACKSPACE: Key = SDLK_BACKSPACE as Key;
13pub const KEY_TAB: Key = SDLK_TAB as Key;
14pub const KEY_SPACE: Key = SDLK_SPACE as Key;
15pub const KEY_EXCLAIM: Key = SDLK_EXCLAIM as Key;
16pub const KEY_QUOTEDBL: Key = SDLK_QUOTEDBL as Key;
17pub const KEY_HASH: Key = SDLK_HASH as Key;
18pub const KEY_PERCENT: Key = SDLK_PERCENT as Key;
19pub const KEY_DOLLAR: Key = SDLK_DOLLAR as Key;
20pub const KEY_AMPERSAND: Key = SDLK_AMPERSAND as Key;
21pub const KEY_QUOTE: Key = SDLK_QUOTE as Key;
22pub const KEY_LEFTPAREN: Key = SDLK_LEFTPAREN as Key;
23pub const KEY_RIGHTPAREN: Key = SDLK_RIGHTPAREN as Key;
24pub const KEY_ASTERISK: Key = SDLK_ASTERISK as Key;
25pub const KEY_PLUS: Key = SDLK_PLUS as Key;
26pub const KEY_COMMA: Key = SDLK_COMMA as Key;
27pub const KEY_MINUS: Key = SDLK_MINUS as Key;
28pub const KEY_PERIOD: Key = SDLK_PERIOD as Key;
29pub const KEY_SLASH: Key = SDLK_SLASH as Key;
30pub const KEY_0: Key = SDLK_0 as Key;
31pub const KEY_1: Key = SDLK_1 as Key;
32pub const KEY_2: Key = SDLK_2 as Key;
33pub const KEY_3: Key = SDLK_3 as Key;
34pub const KEY_4: Key = SDLK_4 as Key;
35pub const KEY_5: Key = SDLK_5 as Key;
36pub const KEY_6: Key = SDLK_6 as Key;
37pub const KEY_7: Key = SDLK_7 as Key;
38pub const KEY_8: Key = SDLK_8 as Key;
39pub const KEY_9: Key = SDLK_9 as Key;
40pub const KEY_COLON: Key = SDLK_COLON as Key;
41pub const KEY_SEMICOLON: Key = SDLK_SEMICOLON as Key;
42pub const KEY_LESS: Key = SDLK_LESS as Key;
43pub const KEY_EQUALS: Key = SDLK_EQUALS as Key;
44pub const KEY_GREATER: Key = SDLK_GREATER as Key;
45pub const KEY_QUESTION: Key = SDLK_QUESTION as Key;
46pub const KEY_AT: Key = SDLK_AT as Key;
47pub const KEY_LEFTBRACKET: Key = SDLK_LEFTBRACKET as Key;
48pub const KEY_BACKSLASH: Key = SDLK_BACKSLASH as Key;
49pub const KEY_RIGHTBRACKET: Key = SDLK_RIGHTBRACKET as Key;
50pub const KEY_CARET: Key = SDLK_CARET as Key;
51pub const KEY_UNDERSCORE: Key = SDLK_UNDERSCORE as Key;
52pub const KEY_BACKQUOTE: Key = SDLK_BACKQUOTE as Key;
53pub const KEY_A: Key = SDLK_a as Key;
54pub const KEY_B: Key = SDLK_b as Key;
55pub const KEY_C: Key = SDLK_c as Key;
56pub const KEY_D: Key = SDLK_d as Key;
57pub const KEY_E: Key = SDLK_e as Key;
58pub const KEY_F: Key = SDLK_f as Key;
59pub const KEY_G: Key = SDLK_g as Key;
60pub const KEY_H: Key = SDLK_h as Key;
61pub const KEY_I: Key = SDLK_i as Key;
62pub const KEY_J: Key = SDLK_j as Key;
63pub const KEY_K: Key = SDLK_k as Key;
64pub const KEY_L: Key = SDLK_l as Key;
65pub const KEY_M: Key = SDLK_m as Key;
66pub const KEY_N: Key = SDLK_n as Key;
67pub const KEY_O: Key = SDLK_o as Key;
68pub const KEY_P: Key = SDLK_p as Key;
69pub const KEY_Q: Key = SDLK_q as Key;
70pub const KEY_R: Key = SDLK_r as Key;
71pub const KEY_S: Key = SDLK_s as Key;
72pub const KEY_T: Key = SDLK_t as Key;
73pub const KEY_U: Key = SDLK_u as Key;
74pub const KEY_V: Key = SDLK_v as Key;
75pub const KEY_W: Key = SDLK_w as Key;
76pub const KEY_X: Key = SDLK_x as Key;
77pub const KEY_Y: Key = SDLK_y as Key;
78pub const KEY_Z: Key = SDLK_z as Key;
79pub const KEY_CAPSLOCK: Key = SDLK_CAPSLOCK as Key;
80pub const KEY_F1: Key = SDLK_F1 as Key;
81pub const KEY_F2: Key = SDLK_F2 as Key;
82pub const KEY_F3: Key = SDLK_F3 as Key;
83pub const KEY_F4: Key = SDLK_F4 as Key;
84pub const KEY_F5: Key = SDLK_F5 as Key;
85pub const KEY_F6: Key = SDLK_F6 as Key;
86pub const KEY_F7: Key = SDLK_F7 as Key;
87pub const KEY_F8: Key = SDLK_F8 as Key;
88pub const KEY_F9: Key = SDLK_F9 as Key;
89pub const KEY_F10: Key = SDLK_F10 as Key;
90pub const KEY_F11: Key = SDLK_F11 as Key;
91pub const KEY_F12: Key = SDLK_F12 as Key;
92pub const KEY_PRINTSCREEN: Key = SDLK_PRINTSCREEN as Key;
93pub const KEY_SCROLLLOCK: Key = SDLK_SCROLLLOCK as Key;
94pub const KEY_PAUSE: Key = SDLK_PAUSE as Key;
95pub const KEY_INSERT: Key = SDLK_INSERT as Key;
96pub const KEY_HOME: Key = SDLK_HOME as Key;
97pub const KEY_PAGEUP: Key = SDLK_PAGEUP as Key;
98pub const KEY_DELETE: Key = SDLK_DELETE as Key;
99pub const KEY_END: Key = SDLK_END as Key;
100pub const KEY_PAGEDOWN: Key = SDLK_PAGEDOWN as Key;
101pub const KEY_RIGHT: Key = SDLK_RIGHT as Key;
102pub const KEY_LEFT: Key = SDLK_LEFT as Key;
103pub const KEY_DOWN: Key = SDLK_DOWN as Key;
104pub const KEY_UP: Key = SDLK_UP as Key;
105pub const KEY_NUMLOCKCLEAR: Key = SDLK_NUMLOCKCLEAR as Key;
106pub const KEY_KP_DIVIDE: Key = SDLK_KP_DIVIDE as Key;
107pub const KEY_KP_MULTIPLY: Key = SDLK_KP_MULTIPLY as Key;
108pub const KEY_KP_MINUS: Key = SDLK_KP_MINUS as Key;
109pub const KEY_KP_PLUS: Key = SDLK_KP_PLUS as Key;
110pub const KEY_KP_ENTER: Key = SDLK_KP_ENTER as Key;
111pub const KEY_KP_1: Key = SDLK_KP_1 as Key;
112pub const KEY_KP_2: Key = SDLK_KP_2 as Key;
113pub const KEY_KP_3: Key = SDLK_KP_3 as Key;
114pub const KEY_KP_4: Key = SDLK_KP_4 as Key;
115pub const KEY_KP_5: Key = SDLK_KP_5 as Key;
116pub const KEY_KP_6: Key = SDLK_KP_6 as Key;
117pub const KEY_KP_7: Key = SDLK_KP_7 as Key;
118pub const KEY_KP_8: Key = SDLK_KP_8 as Key;
119pub const KEY_KP_9: Key = SDLK_KP_9 as Key;
120pub const KEY_KP_0: Key = SDLK_KP_0 as Key;
121pub const KEY_KP_PERIOD: Key = SDLK_KP_PERIOD as Key;
122pub const KEY_APPLICATION: Key = SDLK_APPLICATION as Key;
123pub const KEY_POWER: Key = SDLK_POWER as Key;
124pub const KEY_KP_EQUALS: Key = SDLK_KP_EQUALS as Key;
125pub const KEY_F13: Key = SDLK_F13 as Key;
126pub const KEY_F14: Key = SDLK_F14 as Key;
127pub const KEY_F15: Key = SDLK_F15 as Key;
128pub const KEY_F16: Key = SDLK_F16 as Key;
129pub const KEY_F17: Key = SDLK_F17 as Key;
130pub const KEY_F18: Key = SDLK_F18 as Key;
131pub const KEY_F19: Key = SDLK_F19 as Key;
132pub const KEY_F20: Key = SDLK_F20 as Key;
133pub const KEY_F21: Key = SDLK_F21 as Key;
134pub const KEY_F22: Key = SDLK_F22 as Key;
135pub const KEY_F23: Key = SDLK_F23 as Key;
136pub const KEY_F24: Key = SDLK_F24 as Key;
137pub const KEY_EXECUTE: Key = SDLK_EXECUTE as Key;
138pub const KEY_HELP: Key = SDLK_HELP as Key;
139pub const KEY_MENU: Key = SDLK_MENU as Key;
140pub const KEY_SELECT: Key = SDLK_SELECT as Key;
141pub const KEY_STOP: Key = SDLK_STOP as Key;
142pub const KEY_AGAIN: Key = SDLK_AGAIN as Key;
143pub const KEY_UNDO: Key = SDLK_UNDO as Key;
144pub const KEY_CUT: Key = SDLK_CUT as Key;
145pub const KEY_COPY: Key = SDLK_COPY as Key;
146pub const KEY_PASTE: Key = SDLK_PASTE as Key;
147pub const KEY_FIND: Key = SDLK_FIND as Key;
148pub const KEY_MUTE: Key = SDLK_MUTE as Key;
149pub const KEY_VOLUMEUP: Key = SDLK_VOLUMEUP as Key;
150pub const KEY_VOLUMEDOWN: Key = SDLK_VOLUMEDOWN as Key;
151pub const KEY_KP_COMMA: Key = SDLK_KP_COMMA as Key;
152pub const KEY_KP_EQUALSAS400: Key = SDLK_KP_EQUALSAS400 as Key;
153pub const KEY_ALTERASE: Key = SDLK_ALTERASE as Key;
154pub const KEY_SYSREQ: Key = SDLK_SYSREQ as Key;
155pub const KEY_CANCEL: Key = SDLK_CANCEL as Key;
156pub const KEY_CLEAR: Key = SDLK_CLEAR as Key;
157pub const KEY_PRIOR: Key = SDLK_PRIOR as Key;
158pub const KEY_RETURN2: Key = SDLK_RETURN2 as Key;
159pub const KEY_SEPARATOR: Key = SDLK_SEPARATOR as Key;
160pub const KEY_OUT: Key = SDLK_OUT as Key;
161pub const KEY_OPER: Key = SDLK_OPER as Key;
162pub const KEY_CLEARAGAIN: Key = SDLK_CLEARAGAIN as Key;
163pub const KEY_CRSEL: Key = SDLK_CRSEL as Key;
164pub const KEY_EXSEL: Key = SDLK_EXSEL as Key;
165pub const KEY_KP_00: Key = SDLK_KP_00 as Key;
166pub const KEY_KP_000: Key = SDLK_KP_000 as Key;
167pub const KEY_THOUSANDSSEPARATOR: Key = SDLK_THOUSANDSSEPARATOR as Key;
168pub const KEY_DECIMALSEPARATOR: Key = SDLK_DECIMALSEPARATOR as Key;
169pub const KEY_CURRENCYUNIT: Key = SDLK_CURRENCYUNIT as Key;
170pub const KEY_CURRENCYSUBUNIT: Key = SDLK_CURRENCYSUBUNIT as Key;
171pub const KEY_KP_LEFTPAREN: Key = SDLK_KP_LEFTPAREN as Key;
172pub const KEY_KP_RIGHTPAREN: Key = SDLK_KP_RIGHTPAREN as Key;
173pub const KEY_KP_LEFTBRACE: Key = SDLK_KP_LEFTBRACE as Key;
174pub const KEY_KP_RIGHTBRACE: Key = SDLK_KP_RIGHTBRACE as Key;
175pub const KEY_KP_TAB: Key = SDLK_KP_TAB as Key;
176pub const KEY_KP_BACKSPACE: Key = SDLK_KP_BACKSPACE as Key;
177pub const KEY_KP_A: Key = SDLK_KP_A as Key;
178pub const KEY_KP_B: Key = SDLK_KP_B as Key;
179pub const KEY_KP_C: Key = SDLK_KP_C as Key;
180pub const KEY_KP_D: Key = SDLK_KP_D as Key;
181pub const KEY_KP_E: Key = SDLK_KP_E as Key;
182pub const KEY_KP_F: Key = SDLK_KP_F as Key;
183pub const KEY_KP_XOR: Key = SDLK_KP_XOR as Key;
184pub const KEY_KP_POWER: Key = SDLK_KP_POWER as Key;
185pub const KEY_KP_PERCENT: Key = SDLK_KP_PERCENT as Key;
186pub const KEY_KP_LESS: Key = SDLK_KP_LESS as Key;
187pub const KEY_KP_GREATER: Key = SDLK_KP_GREATER as Key;
188pub const KEY_KP_AMPERSAND: Key = SDLK_KP_AMPERSAND as Key;
189pub const KEY_KP_DBLAMPERSAND: Key = SDLK_KP_DBLAMPERSAND as Key;
190pub const KEY_KP_VERTICALBAR: Key = SDLK_KP_VERTICALBAR as Key;
191pub const KEY_KP_DBLVERTICALBAR: Key = SDLK_KP_DBLVERTICALBAR as Key;
192pub const KEY_KP_COLON: Key = SDLK_KP_COLON as Key;
193pub const KEY_KP_HASH: Key = SDLK_KP_HASH as Key;
194pub const KEY_KP_SPACE: Key = SDLK_KP_SPACE as Key;
195pub const KEY_KP_AT: Key = SDLK_KP_AT as Key;
196pub const KEY_KP_EXCLAM: Key = SDLK_KP_EXCLAM as Key;
197pub const KEY_KP_MEMSTORE: Key = SDLK_KP_MEMSTORE as Key;
198pub const KEY_KP_MEMRECALL: Key = SDLK_KP_MEMRECALL as Key;
199pub const KEY_KP_MEMCLEAR: Key = SDLK_KP_MEMCLEAR as Key;
200pub const KEY_KP_MEMADD: Key = SDLK_KP_MEMADD as Key;
201pub const KEY_KP_MEMSUBTRACT: Key = SDLK_KP_MEMSUBTRACT as Key;
202pub const KEY_KP_MEMMULTIPLY: Key = SDLK_KP_MEMMULTIPLY as Key;
203pub const KEY_KP_MEMDIVIDE: Key = SDLK_KP_MEMDIVIDE as Key;
204pub const KEY_KP_PLUSMINUS: Key = SDLK_KP_PLUSMINUS as Key;
205pub const KEY_KP_CLEAR: Key = SDLK_KP_CLEAR as Key;
206pub const KEY_KP_CLEARENTRY: Key = SDLK_KP_CLEARENTRY as Key;
207pub const KEY_KP_BINARY: Key = SDLK_KP_BINARY as Key;
208pub const KEY_KP_OCTAL: Key = SDLK_KP_OCTAL as Key;
209pub const KEY_KP_DECIMAL: Key = SDLK_KP_DECIMAL as Key;
210pub const KEY_KP_HEXADECIMAL: Key = SDLK_KP_HEXADECIMAL as Key;
211pub const KEY_LCTRL: Key = SDLK_LCTRL as Key;
212pub const KEY_LSHIFT: Key = SDLK_LSHIFT as Key;
213pub const KEY_LALT: Key = SDLK_LALT as Key;
214pub const KEY_LGUI: Key = SDLK_LGUI as Key;
215pub const KEY_RCTRL: Key = SDLK_RCTRL as Key;
216pub const KEY_RSHIFT: Key = SDLK_RSHIFT as Key;
217pub const KEY_RALT: Key = SDLK_RALT as Key;
218pub const KEY_RGUI: Key = SDLK_RGUI as Key;
219pub const KEY_MODE: Key = SDLK_MODE as Key;
220pub const KEY_AUDIONEXT: Key = SDLK_AUDIONEXT as Key;
221pub const KEY_AUDIOPREV: Key = SDLK_AUDIOPREV as Key;
222pub const KEY_AUDIOSTOP: Key = SDLK_AUDIOSTOP as Key;
223pub const KEY_AUDIOPLAY: Key = SDLK_AUDIOPLAY as Key;
224pub const KEY_AUDIOMUTE: Key = SDLK_AUDIOMUTE as Key;
225pub const KEY_MEDIASELECT: Key = SDLK_MEDIASELECT as Key;
226pub const KEY_WWW: Key = SDLK_WWW as Key;
227pub const KEY_MAIL: Key = SDLK_MAIL as Key;
228pub const KEY_CALCULATOR: Key = SDLK_CALCULATOR as Key;
229pub const KEY_COMPUTER: Key = SDLK_COMPUTER as Key;
230pub const KEY_AC_SEARCH: Key = SDLK_AC_SEARCH as Key;
231pub const KEY_AC_HOME: Key = SDLK_AC_HOME as Key;
232pub const KEY_AC_BACK: Key = SDLK_AC_BACK as Key;
233pub const KEY_AC_FORWARD: Key = SDLK_AC_FORWARD as Key;
234pub const KEY_AC_STOP: Key = SDLK_AC_STOP as Key;
235pub const KEY_AC_REFRESH: Key = SDLK_AC_REFRESH as Key;
236pub const KEY_AC_BOOKMARKS: Key = SDLK_AC_BOOKMARKS as Key;
237pub const KEY_BRIGHTNESSDOWN: Key = SDLK_BRIGHTNESSDOWN as Key;
238pub const KEY_BRIGHTNESSUP: Key = SDLK_BRIGHTNESSUP as Key;
239pub const KEY_DISPLAYSWITCH: Key = SDLK_DISPLAYSWITCH as Key;
240pub const KEY_KBDILLUMTOGGLE: Key = SDLK_KBDILLUMTOGGLE as Key;
241pub const KEY_KBDILLUMDOWN: Key = SDLK_KBDILLUMDOWN as Key;
242pub const KEY_KBDILLUMUP: Key = SDLK_KBDILLUMUP as Key;
243pub const KEY_EJECT: Key = SDLK_EJECT as Key;
244pub const KEY_SLEEP: Key = SDLK_SLEEP as Key;
245pub const KEY_APP1: Key = SDLK_APP1 as Key;
246pub const KEY_APP2: Key = SDLK_APP2 as Key;
247pub const KEY_AUDIOREWIND: Key = SDLK_AUDIOREWIND as Key;
248pub const KEY_AUDIOFASTFORWARD: Key = SDLK_AUDIOFASTFORWARD as Key;
249
250pub const SPECIAL_KEY_START_INDEX: Key = 0x5000_0000;
251pub const KEY_NONE: Key = SPECIAL_KEY_START_INDEX;
252pub const KEY_SHIFT: Key = SPECIAL_KEY_START_INDEX + 1;
253pub const KEY_CTRL: Key = SPECIAL_KEY_START_INDEX + 2;
254pub const KEY_ALT: Key = SPECIAL_KEY_START_INDEX + 3;
255pub const KEY_GUI: Key = SPECIAL_KEY_START_INDEX + 4;
256
257// Mouse
258pub const MOUSE_KEY_START_INDEX: Key = 0x5000_0100;
259pub const MOUSE_POS_X: Key = MOUSE_KEY_START_INDEX;
260pub const MOUSE_POS_Y: Key = MOUSE_KEY_START_INDEX + 1;
261pub const MOUSE_WHEEL_X: Key = MOUSE_KEY_START_INDEX + 2;
262pub const MOUSE_WHEEL_Y: Key = MOUSE_KEY_START_INDEX + 3;
263pub const MOUSE_BUTTON_LEFT: Key = MOUSE_KEY_START_INDEX + 4;
264pub const MOUSE_BUTTON_MIDDLE: Key = MOUSE_KEY_START_INDEX + 5;
265pub const MOUSE_BUTTON_RIGHT: Key = MOUSE_KEY_START_INDEX + 6;
266pub const MOUSE_BUTTON_X1: Key = MOUSE_KEY_START_INDEX + 7;
267pub const MOUSE_BUTTON_X2: Key = MOUSE_KEY_START_INDEX + 8;
268
269// Gamepad
270pub const GAMEPAD_KEY_START_INDEX: Key = 0x5000_0200;
271pub const GAMEPAD_KEY_INDEX_INTERVAL: Key = 0x100;
272
273macro_rules! define_gamepad_keys {
274    ($gamepad_name:ident, $start_index:expr) => {
275        paste! {
276            pub const [<$gamepad_name _AXIS_LEFTX>]: Key  = $start_index + 0;
277            pub const [<$gamepad_name _AXIS_LEFTY>]: Key  = $start_index + 1;
278            pub const [<$gamepad_name _AXIS_RIGHTX>]: Key  = $start_index + 2;
279            pub const [<$gamepad_name _AXIS_RIGHTY>]: Key  = $start_index + 3;
280            pub const [<$gamepad_name _AXIS_TRIGGERLEFT>]: Key  = $start_index + 4;
281            pub const [<$gamepad_name _AXIS_TRIGGERRIGHT>]: Key  = $start_index + 5;
282            pub const [<$gamepad_name _BUTTON_A>]: Key  = $start_index + 6;
283            pub const [<$gamepad_name _BUTTON_B>]: Key  = $start_index + 7;
284            pub const [<$gamepad_name _BUTTON_X>]: Key  = $start_index + 8;
285            pub const [<$gamepad_name _BUTTON_Y>]: Key  = $start_index + 9;
286            pub const [<$gamepad_name _BUTTON_BACK>]: Key  = $start_index + 10;
287            pub const [<$gamepad_name _BUTTON_GUIDE>]: Key  = $start_index + 11;
288            pub const [<$gamepad_name _BUTTON_START>]: Key  = $start_index + 12;
289            pub const [<$gamepad_name _BUTTON_LEFTSTICK>]: Key  = $start_index + 13;
290            pub const [<$gamepad_name _BUTTON_RIGHTSTICK>]: Key  = $start_index + 14;
291            pub const [<$gamepad_name _BUTTON_LEFTSHOULDER>]: Key  = $start_index + 15;
292            pub const [<$gamepad_name _BUTTON_RIGHTSHOULDER>]: Key  = $start_index + 16;
293            pub const [<$gamepad_name _BUTTON_DPAD_UP>]: Key  = $start_index + 17;
294            pub const [<$gamepad_name _BUTTON_DPAD_DOWN>]: Key  = $start_index + 18;
295            pub const [<$gamepad_name _BUTTON_DPAD_LEFT>]: Key  = $start_index + 19;
296            pub const [<$gamepad_name _BUTTON_DPAD_RIGHT>]: Key  = $start_index + 20;
297        }
298    };
299}
300
301define_gamepad_keys!(GAMEPAD1, GAMEPAD_KEY_START_INDEX);
302
303define_gamepad_keys!(
304    GAMEPAD2,
305    GAMEPAD_KEY_START_INDEX + GAMEPAD_KEY_INDEX_INTERVAL
306);
307
308define_gamepad_keys!(
309    GAMEPAD3,
310    GAMEPAD_KEY_START_INDEX + GAMEPAD_KEY_INDEX_INTERVAL * 2
311);
312
313define_gamepad_keys!(
314    GAMEPAD4,
315    GAMEPAD_KEY_START_INDEX + GAMEPAD_KEY_INDEX_INTERVAL * 3
316);