logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
use crate::engine::d2::input::Key;

/// Key codes.
pub struct KeyCodes {}

impl KeyCodes {
    pub const A: i32 = 65;
    pub const B: i32 = 66;
    pub const C: i32 = 67;
    pub const D: i32 = 68;
    pub const E: i32 = 69;
    pub const F: i32 = 70;
    pub const G: i32 = 71;
    pub const H: i32 = 72;
    pub const I: i32 = 73;
    pub const J: i32 = 74;
    pub const K: i32 = 75;
    pub const L: i32 = 76;
    pub const M: i32 = 77;
    pub const N: i32 = 78;
    pub const O: i32 = 79;
    pub const P: i32 = 80;
    pub const Q: i32 = 81;
    pub const R: i32 = 82;
    pub const S: i32 = 83;
    pub const T: i32 = 84;
    pub const U: i32 = 85;
    pub const V: i32 = 86;
    pub const W: i32 = 87;
    pub const X: i32 = 88;
    pub const Y: i32 = 89;
    pub const Z: i32 = 90;

    pub const NUMBER_0: i32 = 48;
    pub const NUMBER_1: i32 = 49;
    pub const NUMBER_2: i32 = 50;
    pub const NUMBER_3: i32 = 51;
    pub const NUMBER_4: i32 = 52;
    pub const NUMBER_5: i32 = 53;
    pub const NUMBER_6: i32 = 54;
    pub const NUMBER_7: i32 = 55;
    pub const NUMBER_8: i32 = 56;
    pub const NUMBER_9: i32 = 57;

    pub const NUMPAD_0: i32 = 96;
    pub const NUMPAD_1: i32 = 97;
    pub const NUMPAD_2: i32 = 98;
    pub const NUMPAD_3: i32 = 99;
    pub const NUMPAD_4: i32 = 100;
    pub const NUMPAD_5: i32 = 101;
    pub const NUMPAD_6: i32 = 102;
    pub const NUMPAD_7: i32 = 103;
    pub const NUMPAD_8: i32 = 104;
    pub const NUMPAD_9: i32 = 105;

    pub const NUMPAD_ADD: i32 = 107;
    pub const NUMPAD_DECIMAL: i32 = 110;
    pub const NUMPAD_DIVIDE: i32 = 111;
    pub const NUMPAD_ENTER: i32 = 108;
    pub const NUMPAD_MULTIPLY: i32 = 106;
    pub const NUMPAD_SUBTRACT: i32 = 109;

    pub const F1: i32 = 112;
    pub const F2: i32 = 113;
    pub const F3: i32 = 114;
    pub const F4: i32 = 115;
    pub const F5: i32 = 116;
    pub const F6: i32 = 117;
    pub const F7: i32 = 118;
    pub const F8: i32 = 119;
    pub const F9: i32 = 120;
    pub const F10: i32 = 121;
    pub const F11: i32 = 122;
    pub const F12: i32 = 123;
    pub const F13: i32 = 124;
    pub const F14: i32 = 125;
    pub const F15: i32 = 126;

    pub const LEFT: i32 = 37;
    pub const UP: i32 = 38;
    pub const RIGHT: i32 = 39;
    pub const DOWN: i32 = 40;

    pub const ALT: i32 = 18;
    pub const BACKQUOTE: i32 = 192;
    pub const BACKSLASH: i32 = 220;
    pub const BACKSPACE: i32 = 8;
    pub const CAPS_LOCK: i32 = 20;
    pub const COMMA: i32 = 188;
    pub const COMMAND: i32 = 15;
    pub const CONTROL: i32 = 17;
    pub const DELETE: i32 = 46;
    pub const END: i32 = 35;
    pub const ENTER: i32 = 13;
    pub const EQUALS: i32 = 187;
    pub const ESCAPE: i32 = 27;
    pub const HOME: i32 = 36;
    pub const INSERT: i32 = 45;
    pub const LEFT_BRACKET: i32 = 219;
    pub const MINUS: i32 = 189;
    pub const PAGE_DOWN: i32 = 34;
    pub const PAGE_UP: i32 = 33;
    pub const PERIOD: i32 = 190;
    pub const QUOTE: i32 = 222;
    pub const RIGHT_BRACKET: i32 = 221;
    pub const SEMICOLON: i32 = 186;
    pub const SHIFT: i32 = 16;
    pub const SLASH: i32 = 191;
    pub const SPACE: i32 = 32;
    pub const TAB: i32 = 9;

    // Android keys (AIR only)
    pub const BACK: i32 = 0x01000016;
    pub const MENU: i32 = 0x01000012;
    pub const SEARCH: i32 = 0x0100001f;

    // static
    pub fn to_key(keycode: i32) -> Key {
        match keycode {
            Self::A => Key::A,
            Self::B => Key::B,
            Self::C => Key::C,
            Self::D => Key::D,
            Self::E => Key::E,
            Self::F => Key::F,
            Self::G => Key::G,
            Self::H => Key::H,
            Self::I => Key::I,
            Self::J => Key::J,
            Self::K => Key::K,
            Self::L => Key::L,
            Self::M => Key::M,
            Self::N => Key::N,
            Self::O => Key::O,
            Self::P => Key::P,
            Self::Q => Key::Q,
            Self::R => Key::R,
            Self::S => Key::S,
            Self::T => Key::T,
            Self::U => Key::U,
            Self::V => Key::V,
            Self::W => Key::W,
            Self::X => Key::X,
            Self::Y => Key::Y,
            Self::Z => Key::Z,

            Self::NUMBER_0 => Key::Number0,
            Self::NUMBER_1 => Key::Number1,
            Self::NUMBER_2 => Key::Number2,
            Self::NUMBER_3 => Key::Number3,
            Self::NUMBER_4 => Key::Number4,
            Self::NUMBER_5 => Key::Number5,
            Self::NUMBER_6 => Key::Number6,
            Self::NUMBER_7 => Key::Number7,
            Self::NUMBER_8 => Key::Number8,
            Self::NUMBER_9 => Key::Number9,

            Self::NUMPAD_0 => Key::Numpad0,
            Self::NUMPAD_1 => Key::Numpad1,
            Self::NUMPAD_2 => Key::Numpad2,
            Self::NUMPAD_3 => Key::Numpad3,
            Self::NUMPAD_4 => Key::Numpad4,
            Self::NUMPAD_5 => Key::Numpad5,
            Self::NUMPAD_6 => Key::Numpad6,
            Self::NUMPAD_7 => Key::Numpad7,
            Self::NUMPAD_8 => Key::Numpad8,
            Self::NUMPAD_9 => Key::Numpad9,

            Self::NUMPAD_ADD => Key::NumpadAdd,
            Self::NUMPAD_DECIMAL => Key::NumpadDecimal,
            Self::NUMPAD_DIVIDE => Key::NumpadDivide,
            Self::NUMPAD_ENTER => Key::NumpadEnter,
            Self::NUMPAD_MULTIPLY => Key::NumpadMultiply,
            Self::NUMPAD_SUBTRACT => Key::NumpadSubtract,

            Self::F1 => Key::F1,
            Self::F2 => Key::F2,
            Self::F3 => Key::F3,
            Self::F4 => Key::F4,
            Self::F5 => Key::F5,
            Self::F6 => Key::F6,
            Self::F7 => Key::F7,
            Self::F8 => Key::F8,
            Self::F9 => Key::F9,
            Self::F10 => Key::F10,
            Self::F11 => Key::F11,
            Self::F12 => Key::F12,

            Self::LEFT => Key::Left,
            Self::UP => Key::Up,
            Self::RIGHT => Key::Right,
            Self::DOWN => Key::Down,

            Self::ALT => Key::Alt,
            Self::BACKQUOTE => Key::Backquote,
            Self::BACKSLASH => Key::Backslash,
            Self::BACKSPACE => Key::Backspace,
            Self::CAPS_LOCK => Key::CapsLock,
            Self::COMMA => Key::Comma,
            Self::COMMAND => Key::Command,
            Self::CONTROL => Key::Control,
            Self::DELETE => Key::Delete,
            Self::END => Key::End,
            Self::ENTER => Key::Enter,
            Self::EQUALS => Key::Equals,
            Self::ESCAPE => Key::Escape,
            Self::HOME => Key::Home,
            Self::INSERT => Key::Insert,
            Self::LEFT_BRACKET => Key::LeftBracket,
            Self::MINUS => Key::Minus,
            Self::PAGE_DOWN => Key::PageDown,
            Self::PAGE_UP => Key::PageUp,
            Self::PERIOD => Key::Period,
            Self::QUOTE => Key::Quote,
            Self::RIGHT_BRACKET => Key::RightBracket,
            Self::SEMICOLON => Key::Semicolon,
            Self::SHIFT => Key::Shift,
            Self::SLASH => Key::Slash,
            Self::SPACE => Key::Space,
            Self::TAB => Key::Tab,

            Self::MENU => Key::Menu,
            Self::SEARCH => Key::Search,
            _ => Key::Unknown { keycode },
        }
    }

    // static
    pub fn to_key_code(key: Key) -> i32 {
        match key {
            Key::A => Self::A,
            Key::B => Self::B,
            Key::C => Self::C,
            Key::D => Self::D,
            Key::E => Self::E,
            Key::F => Self::F,
            Key::G => Self::G,
            Key::H => Self::H,
            Key::I => Self::I,
            Key::J => Self::J,
            Key::K => Self::K,
            Key::L => Self::L,
            Key::M => Self::M,
            Key::N => Self::N,
            Key::O => Self::O,
            Key::P => Self::P,
            Key::Q => Self::Q,
            Key::R => Self::R,
            Key::S => Self::S,
            Key::T => Self::T,
            Key::U => Self::U,
            Key::V => Self::V,
            Key::W => Self::W,
            Key::X => Self::X,
            Key::Y => Self::Y,
            Key::Z => Self::Z,

            Key::Number0 => Self::NUMBER_0,
            Key::Number1 => Self::NUMBER_1,
            Key::Number2 => Self::NUMBER_2,
            Key::Number3 => Self::NUMBER_3,
            Key::Number4 => Self::NUMBER_4,
            Key::Number5 => Self::NUMBER_5,
            Key::Number6 => Self::NUMBER_6,
            Key::Number7 => Self::NUMBER_7,
            Key::Number8 => Self::NUMBER_8,
            Key::Number9 => Self::NUMBER_9,

            Key::Numpad0 => Self::NUMPAD_0,
            Key::Numpad1 => Self::NUMPAD_1,
            Key::Numpad2 => Self::NUMPAD_2,
            Key::Numpad3 => Self::NUMPAD_3,
            Key::Numpad4 => Self::NUMPAD_4,
            Key::Numpad5 => Self::NUMPAD_5,
            Key::Numpad6 => Self::NUMPAD_6,
            Key::Numpad7 => Self::NUMPAD_7,
            Key::Numpad8 => Self::NUMPAD_8,
            Key::Numpad9 => Self::NUMPAD_9,

            Key::NumpadAdd => Self::NUMPAD_ADD,
            Key::NumpadDecimal => Self::NUMPAD_DECIMAL,
            Key::NumpadDivide => Self::NUMPAD_DIVIDE,
            Key::NumpadEnter => Self::NUMPAD_ENTER,
            Key::NumpadMultiply => Self::NUMPAD_MULTIPLY,
            Key::NumpadSubtract => Self::NUMPAD_SUBTRACT,

            Key::F1 => Self::F1,
            Key::F2 => Self::F2,
            Key::F3 => Self::F3,
            Key::F4 => Self::F4,
            Key::F5 => Self::F5,
            Key::F6 => Self::F6,
            Key::F7 => Self::F7,
            Key::F8 => Self::F8,
            Key::F9 => Self::F9,
            Key::F10 => Self::F10,
            Key::F11 => Self::F11,
            Key::F12 => Self::F12,
            Key::F13 => Self::F13,
            Key::F14 => Self::F14,
            Key::F15 => Self::F15,

            Key::Left => Self::LEFT,
            Key::Up => Self::UP,
            Key::Right => Self::RIGHT,
            Key::Down => Self::DOWN,

            Key::Alt => Self::ALT,
            Key::Backquote => Self::BACKQUOTE,
            Key::Backslash => Self::BACKSLASH,
            Key::Backspace => Self::BACKSPACE,
            Key::CapsLock => Self::CAPS_LOCK,
            Key::Comma => Self::COMMA,
            Key::Command => Self::COMMAND,
            Key::Control => Self::CONTROL,
            Key::Delete => Self::DELETE,
            Key::End => Self::END,
            Key::Enter => Self::ENTER,
            Key::Equals => Self::EQUALS,
            Key::Escape => Self::ESCAPE,
            Key::Home => Self::HOME,
            Key::Insert => Self::INSERT,
            Key::LeftBracket => Self::LEFT_BRACKET,
            Key::Minus => Self::MINUS,
            Key::PageDown => Self::PAGE_DOWN,
            Key::PageUp => Self::PAGE_UP,
            Key::Period => Self::PERIOD,
            Key::Quote => Self::QUOTE,
            Key::RightBracket => Self::RIGHT_BRACKET,
            Key::Semicolon => Self::SEMICOLON,
            Key::Shift => Self::SHIFT,
            Key::Slash => Self::SLASH,
            Key::Space => Self::SPACE,
            Key::Tab => Self::TAB,

            Key::Menu => Self::MENU,
            Key::Search => Self::SEARCH,

            Key::Unknown { keycode } => keycode,
        }
    }
}