GCC Code Coverage Report


Directory: src/gate/
File: src/gate/inputs.c
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 48 60 80.0%
Functions: 4 4 100.0%
Branches: 19 36 52.8%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/inputs.h"
30 #include "gate/strings.h"
31 #include "gate/results.h"
32
33 #if defined(GATE_SYS_WIN)
34 # define GATE_INPUT_WINAPI_IMPL 1
35 #elif defined(GATE_SYS_POSIX)
36 # define GATE_INPUT_POSIX_IMPL 1
37 #else
38 # define GATE_INPUT_NO_IMPL 1
39 #endif
40
41
42 struct gate_vt100_key_mapping
43 {
44 char const* text;
45 gate_input_keycode_t key;
46 gate_input_keystates_t kbdstates;
47 gate_char32_t character;
48 };
49
50 static struct gate_vt100_key_mapping const vt100_keys[] =
51 {
52 { "A", GATE_KBD_KEY_A, GATE_KBD_KEYSTATE_SHIFT, 'A' },
53 { "B", GATE_KBD_KEY_B, GATE_KBD_KEYSTATE_SHIFT, 'B' },
54 { "C", GATE_KBD_KEY_C, GATE_KBD_KEYSTATE_SHIFT, 'C' },
55 { "D", GATE_KBD_KEY_D, GATE_KBD_KEYSTATE_SHIFT, 'D' },
56 { "E", GATE_KBD_KEY_E, GATE_KBD_KEYSTATE_SHIFT, 'E' },
57 { "F", GATE_KBD_KEY_F, GATE_KBD_KEYSTATE_SHIFT, 'F' },
58 { "G", GATE_KBD_KEY_G, GATE_KBD_KEYSTATE_SHIFT, 'G' },
59 { "H", GATE_KBD_KEY_H, GATE_KBD_KEYSTATE_SHIFT, 'H' },
60 { "I", GATE_KBD_KEY_I, GATE_KBD_KEYSTATE_SHIFT, 'I' },
61 { "J", GATE_KBD_KEY_J, GATE_KBD_KEYSTATE_SHIFT, 'J' },
62 { "K", GATE_KBD_KEY_K, GATE_KBD_KEYSTATE_SHIFT, 'K' },
63 { "L", GATE_KBD_KEY_L, GATE_KBD_KEYSTATE_SHIFT, 'L' },
64 { "M", GATE_KBD_KEY_M, GATE_KBD_KEYSTATE_SHIFT, 'M' },
65 { "N", GATE_KBD_KEY_N, GATE_KBD_KEYSTATE_SHIFT, 'N' },
66 { "O", GATE_KBD_KEY_O, GATE_KBD_KEYSTATE_SHIFT, 'O' },
67 { "P", GATE_KBD_KEY_P, GATE_KBD_KEYSTATE_SHIFT, 'P' },
68 { "Q", GATE_KBD_KEY_Q, GATE_KBD_KEYSTATE_SHIFT, 'Q' },
69 { "R", GATE_KBD_KEY_R, GATE_KBD_KEYSTATE_SHIFT, 'R' },
70 { "S", GATE_KBD_KEY_S, GATE_KBD_KEYSTATE_SHIFT, 'S' },
71 { "T", GATE_KBD_KEY_T, GATE_KBD_KEYSTATE_SHIFT, 'T' },
72 { "U", GATE_KBD_KEY_U, GATE_KBD_KEYSTATE_SHIFT, 'U' },
73 { "V", GATE_KBD_KEY_V, GATE_KBD_KEYSTATE_SHIFT, 'V' },
74 { "W", GATE_KBD_KEY_W, GATE_KBD_KEYSTATE_SHIFT, 'W' },
75 { "X", GATE_KBD_KEY_X, GATE_KBD_KEYSTATE_SHIFT, 'X' },
76 { "Y", GATE_KBD_KEY_Y, GATE_KBD_KEYSTATE_SHIFT, 'Y' },
77 { "Z", GATE_KBD_KEY_Z, GATE_KBD_KEYSTATE_SHIFT, 'Z' },
78 { "a", GATE_KBD_KEY_A, 0, 'A' },
79 { "b", GATE_KBD_KEY_B, 0, 'B' },
80 { "c", GATE_KBD_KEY_C, 0, 'C' },
81 { "d", GATE_KBD_KEY_D, 0, 'D' },
82 { "e", GATE_KBD_KEY_E, 0, 'E' },
83 { "f", GATE_KBD_KEY_F, 0, 'F' },
84 { "g", GATE_KBD_KEY_G, 0, 'G' },
85 { "h", GATE_KBD_KEY_H, 0, 'H' },
86 { "i", GATE_KBD_KEY_I, 0, 'I' },
87 { "j", GATE_KBD_KEY_J, 0, 'J' },
88 { "k", GATE_KBD_KEY_K, 0, 'K' },
89 { "l", GATE_KBD_KEY_L, 0, 'L' },
90 { "m", GATE_KBD_KEY_M, 0, 'M' },
91 { "n", GATE_KBD_KEY_N, 0, 'N' },
92 { "o", GATE_KBD_KEY_O, 0, 'O' },
93 { "p", GATE_KBD_KEY_P, 0, 'P' },
94 { "q", GATE_KBD_KEY_Q, 0, 'Q' },
95 { "r", GATE_KBD_KEY_R, 0, 'R' },
96 { "s", GATE_KBD_KEY_S, 0, 'S' },
97 { "t", GATE_KBD_KEY_T, 0, 'T' },
98 { "u", GATE_KBD_KEY_U, 0, 'U' },
99 { "v", GATE_KBD_KEY_V, 0, 'V' },
100 { "w", GATE_KBD_KEY_W, 0, 'W' },
101 { "x", GATE_KBD_KEY_X, 0, 'X' },
102 { "y", GATE_KBD_KEY_Y, 0, 'Y' },
103 { "z", GATE_KBD_KEY_Z, 0, 'Z' },
104 { "0", GATE_KBD_KEY_0, 0, '0' },
105 { "1", GATE_KBD_KEY_1, 0, '1' },
106 { "2", GATE_KBD_KEY_2, 0, '2' },
107 { "3", GATE_KBD_KEY_3, 0, '3' },
108 { "4", GATE_KBD_KEY_4, 0, '4' },
109 { "5", GATE_KBD_KEY_5, 0, '5' },
110 { "6", GATE_KBD_KEY_6, 0, '6' },
111 { "7", GATE_KBD_KEY_7, 0, '7' },
112 { "8", GATE_KBD_KEY_8, 0, '8' },
113 { "9", GATE_KBD_KEY_9, 0, '9' },
114
115 { "\x1B\x5B\x41", GATE_KBD_KEY_UP, 0 },
116 { "\x1B\x5B\x42", GATE_KBD_KEY_DOWN, 0 },
117 { "\x1B\x5B\x43", GATE_KBD_KEY_RIGHT, 0 },
118 { "\x1B\x5B\x44", GATE_KBD_KEY_LEFT, 0 },
119 { "\x1B\x5B\x48", GATE_KBD_KEY_HOME, 0 },
120 { "\x1B\x5B\x46", GATE_KBD_KEY_END, 0 },
121 { "\x1B\x5B\x31\x7E", GATE_KBD_KEY_HOME, 0 },
122 { "\x1B\x5B\x32\x7E", GATE_KBD_KEY_INSERT, 0 },
123 { "\x1B\x5B\x33\x7E", GATE_KBD_KEY_DELETE, 0 },
124 { "\x1B\x5B\x34\x7E", GATE_KBD_KEY_END, 0 },
125 { "\x1B\x5B\x35\x7E", GATE_KBD_KEY_PGUP, 0 },
126 { "\x1B\x5B\x36\x7E", GATE_KBD_KEY_PGDOWN, 0 },
127 { "\x1B\x30", GATE_KBD_KEY_0, GATE_KBD_KEYSTATE_MENU, '0' },
128 { "\x1B\x31", GATE_KBD_KEY_1, GATE_KBD_KEYSTATE_MENU, '1' },
129 { "\x1B\x32", GATE_KBD_KEY_2, GATE_KBD_KEYSTATE_MENU, '2' },
130 { "\x1B\x33", GATE_KBD_KEY_3, GATE_KBD_KEYSTATE_MENU, '3' },
131 { "\x1B\x34", GATE_KBD_KEY_4, GATE_KBD_KEYSTATE_MENU, '4' },
132 { "\x1B\x35", GATE_KBD_KEY_5, GATE_KBD_KEYSTATE_MENU, '5' },
133 { "\x1B\x36", GATE_KBD_KEY_6, GATE_KBD_KEYSTATE_MENU, '6' },
134 { "\x1B\x37", GATE_KBD_KEY_7, GATE_KBD_KEYSTATE_MENU, '7' },
135 { "\x1B\x38", GATE_KBD_KEY_8, GATE_KBD_KEYSTATE_MENU, '8' },
136 { "\x1B\x39", GATE_KBD_KEY_9, GATE_KBD_KEYSTATE_MENU, '9' },
137 { "\x1B\x41", GATE_KBD_KEY_A, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'A' },
138 { "\x1B\x42", GATE_KBD_KEY_B, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'B' },
139 { "\x1B\x43", GATE_KBD_KEY_C, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'C' },
140 { "\x1B\x44", GATE_KBD_KEY_D, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'D' },
141 { "\x1B\x45", GATE_KBD_KEY_E, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'E' },
142 { "\x1B\x46", GATE_KBD_KEY_F, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'F' },
143 { "\x1B\x47", GATE_KBD_KEY_G, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'G' },
144 { "\x1B\x48", GATE_KBD_KEY_H, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'H' },
145 { "\x1B\x49", GATE_KBD_KEY_I, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'I' },
146 { "\x1B\x4a", GATE_KBD_KEY_J, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'J' },
147 { "\x1B\x4b", GATE_KBD_KEY_K, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'K' },
148 { "\x1B\x4c", GATE_KBD_KEY_L, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'L' },
149 { "\x1B\x4d", GATE_KBD_KEY_M, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'M' },
150 { "\x1B\x4e", GATE_KBD_KEY_N, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'N' },
151 { "\x1B\x4f", GATE_KBD_KEY_O, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'O' },
152 { "\x1B\x50", GATE_KBD_KEY_P, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'P' },
153 { "\x1B\x51", GATE_KBD_KEY_Q, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'Q' },
154 { "\x1B\x52", GATE_KBD_KEY_R, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'R' },
155 { "\x1B\x53", GATE_KBD_KEY_S, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'S' },
156 { "\x1B\x54", GATE_KBD_KEY_T, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'T' },
157 { "\x1B\x55", GATE_KBD_KEY_U, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'U' },
158 { "\x1B\x56", GATE_KBD_KEY_V, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'V' },
159 { "\x1B\x57", GATE_KBD_KEY_W, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'W' },
160 { "\x1B\x58", GATE_KBD_KEY_X, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'X' },
161 { "\x1B\x59", GATE_KBD_KEY_Y, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'Y' },
162 { "\x1B\x5a", GATE_KBD_KEY_Z, GATE_KBD_KEYSTATE_MENU | GATE_KBD_KEYSTATE_SHIFT, 'Z' },
163 { "\x1B\x61", GATE_KBD_KEY_A, GATE_KBD_KEYSTATE_MENU, 'A' },
164 { "\x1B\x62", GATE_KBD_KEY_B, GATE_KBD_KEYSTATE_MENU, 'B' },
165 { "\x1B\x63", GATE_KBD_KEY_C, GATE_KBD_KEYSTATE_MENU, 'C' },
166 { "\x1B\x64", GATE_KBD_KEY_D, GATE_KBD_KEYSTATE_MENU, 'D' },
167 { "\x1B\x65", GATE_KBD_KEY_E, GATE_KBD_KEYSTATE_MENU, 'E' },
168 { "\x1B\x66", GATE_KBD_KEY_F, GATE_KBD_KEYSTATE_MENU, 'F' },
169 { "\x1B\x67", GATE_KBD_KEY_G, GATE_KBD_KEYSTATE_MENU, 'G' },
170 { "\x1B\x68", GATE_KBD_KEY_H, GATE_KBD_KEYSTATE_MENU, 'H' },
171 { "\x1B\x69", GATE_KBD_KEY_I, GATE_KBD_KEYSTATE_MENU, 'I' },
172 { "\x1B\x6a", GATE_KBD_KEY_J, GATE_KBD_KEYSTATE_MENU, 'J' },
173 { "\x1B\x6b", GATE_KBD_KEY_K, GATE_KBD_KEYSTATE_MENU, 'K' },
174 { "\x1B\x6c", GATE_KBD_KEY_L, GATE_KBD_KEYSTATE_MENU, 'L' },
175 { "\x1B\x6d", GATE_KBD_KEY_M, GATE_KBD_KEYSTATE_MENU, 'M' },
176 { "\x1B\x6e", GATE_KBD_KEY_N, GATE_KBD_KEYSTATE_MENU, 'N' },
177 { "\x1B\x6f", GATE_KBD_KEY_O, GATE_KBD_KEYSTATE_MENU, 'O' },
178 { "\x1B\x70", GATE_KBD_KEY_P, GATE_KBD_KEYSTATE_MENU, 'P' },
179 { "\x1B\x71", GATE_KBD_KEY_Q, GATE_KBD_KEYSTATE_MENU, 'Q' },
180 { "\x1B\x72", GATE_KBD_KEY_R, GATE_KBD_KEYSTATE_MENU, 'R' },
181 { "\x1B\x73", GATE_KBD_KEY_S, GATE_KBD_KEYSTATE_MENU, 'S' },
182 { "\x1B\x74", GATE_KBD_KEY_T, GATE_KBD_KEYSTATE_MENU, 'T' },
183 { "\x1B\x75", GATE_KBD_KEY_U, GATE_KBD_KEYSTATE_MENU, 'U' },
184 { "\x1B\x76", GATE_KBD_KEY_V, GATE_KBD_KEYSTATE_MENU, 'V' },
185 { "\x1B\x77", GATE_KBD_KEY_W, GATE_KBD_KEYSTATE_MENU, 'W' },
186 { "\x1B\x78", GATE_KBD_KEY_X, GATE_KBD_KEYSTATE_MENU, 'X' },
187 { "\x1B\x79", GATE_KBD_KEY_Y, GATE_KBD_KEYSTATE_MENU, 'Y' },
188 { "\x1B\x7a", GATE_KBD_KEY_Z, GATE_KBD_KEYSTATE_MENU, 'Z' },
189 { "\x01", GATE_KBD_KEY_A, GATE_KBD_KEYSTATE_CTRL, 'A' },
190 { "\x02", GATE_KBD_KEY_B, GATE_KBD_KEYSTATE_CTRL, 'B' },
191 { "\x03", GATE_KBD_KEY_C, GATE_KBD_KEYSTATE_CTRL, 'C' },
192 { "\x04", GATE_KBD_KEY_D, GATE_KBD_KEYSTATE_CTRL, 'D' },
193 { "\x05", GATE_KBD_KEY_E, GATE_KBD_KEYSTATE_CTRL, 'E' },
194 { "\x06", GATE_KBD_KEY_F, GATE_KBD_KEYSTATE_CTRL, 'F' },
195 { "\x07", GATE_KBD_KEY_G, GATE_KBD_KEYSTATE_CTRL, 'G' },
196 { "\x08", GATE_KBD_KEY_H, GATE_KBD_KEYSTATE_CTRL, 'H' },
197 { "\x09", GATE_KBD_KEY_I, GATE_KBD_KEYSTATE_CTRL, 'I' },
198 { "\x0a", GATE_KBD_KEY_J, GATE_KBD_KEYSTATE_CTRL, 'J' },
199 { "\x0b", GATE_KBD_KEY_K, GATE_KBD_KEYSTATE_CTRL, 'K' },
200 { "\x0c", GATE_KBD_KEY_L, GATE_KBD_KEYSTATE_CTRL, 'L' },
201 { "\x0d", GATE_KBD_KEY_M, GATE_KBD_KEYSTATE_CTRL, 'M' },
202 { "\x0e", GATE_KBD_KEY_N, GATE_KBD_KEYSTATE_CTRL, 'N' },
203 { "\x0f", GATE_KBD_KEY_O, GATE_KBD_KEYSTATE_CTRL, 'O' },
204 { "\x10", GATE_KBD_KEY_P, GATE_KBD_KEYSTATE_CTRL, 'P' },
205 { "\x11", GATE_KBD_KEY_Q, GATE_KBD_KEYSTATE_CTRL, 'Q' },
206 { "\x12", GATE_KBD_KEY_R, GATE_KBD_KEYSTATE_CTRL, 'R' },
207 { "\x13", GATE_KBD_KEY_S, GATE_KBD_KEYSTATE_CTRL, 'S' },
208 { "\x14", GATE_KBD_KEY_T, GATE_KBD_KEYSTATE_CTRL, 'T' },
209 { "\x15", GATE_KBD_KEY_U, GATE_KBD_KEYSTATE_CTRL, 'U' },
210 { "\x16", GATE_KBD_KEY_V, GATE_KBD_KEYSTATE_CTRL, 'V' },
211 { "\x17", GATE_KBD_KEY_W, GATE_KBD_KEYSTATE_CTRL, 'W' },
212 { "\x18", GATE_KBD_KEY_X, GATE_KBD_KEYSTATE_CTRL, 'X' },
213 { "\x19", GATE_KBD_KEY_Y, GATE_KBD_KEYSTATE_CTRL, 'Y' },
214 { "\x1a", GATE_KBD_KEY_Z, GATE_KBD_KEYSTATE_CTRL, 'Z' },
215 { "\x1B\x4F\x50", GATE_KBD_KEY_F1, 0 },
216 { "\x1B\x4F\x51", GATE_KBD_KEY_F2, 0 },
217 { "\x1B\x4F\x52", GATE_KBD_KEY_F3, 0 },
218 { "\x1B\x4F\x53", GATE_KBD_KEY_F4, 0 },
219 { "\x1B\x5B\x31\x31\0x7e", GATE_KBD_KEY_F1, 0 },
220 { "\x1B\x5B\x31\x32\0x7e", GATE_KBD_KEY_F2, 0 },
221 { "\x1B\x5B\x31\x33\0x7e", GATE_KBD_KEY_F3, 0 },
222 { "\x1B\x5B\x31\x34\0x7e", GATE_KBD_KEY_F4, 0 },
223 { "\x1B\x5B\x31\x35\x7E", GATE_KBD_KEY_F5, 0 },
224 { "\x1B\x5B\x31\x37\x7E", GATE_KBD_KEY_F6, 0 },
225 { "\x1B\x5B\x31\x38\x7E", GATE_KBD_KEY_F7, 0 },
226 { "\x1B\x5B\x31\x39\x7E", GATE_KBD_KEY_F8, 0 },
227 { "\x1B\x5B\x32\x30\x7E", GATE_KBD_KEY_F9, 0 },
228 { "\x1B\x5B\x32\x31\x7E", GATE_KBD_KEY_F10, 0 },
229 { "\x1B\x5B\x32\x33\x7E", GATE_KBD_KEY_F11, 0 },
230 { "\x1B\x5B\x31\x34\x7E", GATE_KBD_KEY_F12, 0 },
231 { "\x1B\x4F\x50", GATE_KBD_KEY_F1, 0, '\0' },
232 { "\x1B\x4F\x50", GATE_KBD_KEY_F1, 0, '\0' },
233 { "\x1B\x4F\x50", GATE_KBD_KEY_F1, 0, '\0' },
234 { "\x1B\x4F\x50", GATE_KBD_KEY_F1, 0, '\0' },
235 { "\x1B\x4F\x50", GATE_KBD_KEY_F1, 0, '\0' },
236 { "\x1B\x4F\x50", GATE_KBD_KEY_F1, 0, '\0' },
237 };
238 static gate_size_t const vt100_keys_count = sizeof(vt100_keys) / sizeof(vt100_keys[0]);
239
240
241
242 2 gate_size_t gate_keyboard_parse_vt100_symbols(char const* symbols, gate_size_t symbols_count,
243 gate_input_keycode_t* gate_key, gate_input_keystates_t* gate_kbdstates,
244 gate_char32_t* character)
245 {
246 gate_size_t index;
247 gate_size_t textlen;
248 2 gate_char32_t chr32 = 0;
249 2 struct gate_vt100_key_mapping const* ptr_vt100_key = vt100_keys;
250
251
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 for (index = 0; index != vt100_keys_count; ++index, ++ptr_vt100_key)
252 {
253 64 textlen = gate_str_length(ptr_vt100_key->text);
254
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 62 times.
64 if (0 == gate_str_compare(symbols, symbols_count, ptr_vt100_key->text, textlen))
255 {
256
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (gate_key)
257 {
258 2 *gate_key = ptr_vt100_key->key;
259 }
260
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (gate_kbdstates)
261 {
262 2 *gate_kbdstates = ptr_vt100_key->kbdstates;
263 }
264
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (character)
265 {
266 1 *character = ptr_vt100_key->character;
267 }
268 2 return textlen;
269 }
270 }
271 textlen = gate_char_read_utf8(symbols, symbols_count, &chr32);
272 if (textlen > 0)
273 {
274 if (gate_key)
275 {
276 *gate_key = GATE_KBD_KEY_UNKNOWN;
277 }
278 if (gate_kbdstates)
279 {
280 *gate_kbdstates = GATE_KBD_KEYSTATE_NONE;
281 }
282 if (character)
283 {
284 *character = chr32;
285 }
286 return textlen;
287 }
288 return 0;
289 }
290
291 2 gate_size_t gate_keyboard_build_vt100_symbols(gate_input_keycode_t gate_key, gate_input_keystates_t gate_kbdstate,
292 char* symbols_buffer, gate_size_t symbols_buffer_capacity)
293 {
294 gate_size_t index;
295 gate_size_t textlen;
296 2 struct gate_vt100_key_mapping const* ptr_vt100_key = vt100_keys;
297
298
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 for (index = 0; index != vt100_keys_count; ++index, ++ptr_vt100_key)
299 {
300
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
64 if ((gate_key == ptr_vt100_key->key) && (gate_kbdstate == ptr_vt100_key->kbdstates))
301 {
302 2 textlen = gate_str_length(ptr_vt100_key->text);
303
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (symbols_buffer_capacity >= textlen)
304 {
305 2 gate_mem_copy(symbols_buffer, ptr_vt100_key->text, textlen);
306
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (symbols_buffer_capacity > textlen)
307 {
308 2 symbols_buffer[textlen] = 0;
309 }
310 2 return textlen;
311 }
312 }
313 }
314 return 0;
315 }
316
317
318
319
320
321 #if defined(GATE_INPUT_WINAPI_IMPL)
322
323 #ifndef _WIN32_WINNT
324 #define _WIN32_WINNT 0x0400
325 #endif
326 #ifdef _WIN32_IE
327 #undef _WIN32_IE
328 #endif
329 #define _WIN32_IE 0x400
330
331 #include "gate/platforms.h"
332
333 #ifndef VK_BROWSER_BACK
334 #define VK_BROWSER_BACK 0xA6
335 #endif
336 #ifndef VK_BROWSER_FORWARD
337 #define VK_BROWSER_FORWARD 0xA7
338 #endif
339 #ifndef VK_BROWSER_REFRESH
340 #define VK_BROWSER_REFRESH 0xA8
341 #endif
342 #ifndef VK_BROWSER_STOP
343 #define VK_BROWSER_STOP 0xA9
344 #endif
345 #ifndef VK_BROWSER_SEARCH
346 #define VK_BROWSER_SEARCH 0xAA
347 #endif
348 #ifndef VK_BROWSER_FAVORITES
349 #define VK_BROWSER_FAVORITES 0xAB
350 #endif
351 #ifndef VK_BROWSER_HOME
352 #define VK_BROWSER_HOME 0xAC
353 #endif
354 #ifndef VK_VOLUME_MUTE
355 #define VK_VOLUME_MUTE 0xAD
356 #endif
357 #ifndef VK_VOLUME_DOWN
358 #define VK_VOLUME_DOWN 0xAE
359 #endif
360 #ifndef VK_VOLUME_UP
361 #define VK_VOLUME_UP 0xAF
362 #endif
363 #ifndef VK_MEDIA_NEXT_TRACK
364 #define VK_MEDIA_NEXT_TRACK 0xB0
365 #endif
366 #ifndef VK_MEDIA_PREV_TRACK
367 #define VK_MEDIA_PREV_TRACK 0xB1
368 #endif
369 #ifndef VK_MEDIA_STOP
370 #define VK_MEDIA_STOP 0xB2
371 #endif
372 #ifndef VK_MEDIA_PLAY_PAUSE
373 #define VK_MEDIA_PLAY_PAUSE 0xB3
374 #endif
375 #ifndef VK_LAUNCH_MAIL
376 #define VK_LAUNCH_MAIL 0xB4
377 #endif
378 #ifndef VK_LAUNCH_MEDIA_SELECT
379 #define VK_LAUNCH_MEDIA_SELECT 0xB5
380 #endif
381 #ifndef VK_LAUNCH_APP1
382 #define VK_LAUNCH_APP1 0xB6
383 #endif
384 #ifndef VK_LAUNCH_APP2
385 #define VK_LAUNCH_APP2 0xB7
386 #endif
387
388
389 typedef struct gate_KBD_win32_key_mapping
390 {
391 gate_input_keycode_t gate_code;
392 gate_uint32_t native_code;
393 } gate_KBD_win32_key_mapping_t;
394
395 static gate_KBD_win32_key_mapping_t win32_global_vkey_mappings[] = {
396 { GATE_KBD_KEY_BACKSPACE, VK_BACK },
397 { GATE_KBD_KEY_TAB, VK_TAB },
398 { GATE_KBD_KEY_CLEAR, VK_CLEAR },
399 { GATE_KBD_KEY_RETURN, VK_RETURN },
400 { GATE_KBD_KEY_SHIFT, VK_SHIFT },
401 { GATE_KBD_KEY_CTRL, VK_CONTROL },
402 { GATE_KBD_KEY_MENU, VK_MENU },
403 { GATE_KBD_KEY_PAUSE, VK_PAUSE },
404 { GATE_KBD_KEY_CAPITAL, VK_CAPITAL },
405 { GATE_KBD_KEY_ESCAPE, VK_ESCAPE },
406 #if !defined(GATE_SYS_WIN16)
407 { GATE_KBD_KEY_IME_KANA, VK_KANA },
408 { GATE_KBD_KEY_IME_JUNJA, VK_JUNJA },
409 { GATE_KBD_KEY_IME_FINAL, VK_FINAL },
410 { GATE_KBD_KEY_IME_KANJI, VK_KANJI },
411 { GATE_KBD_KEY_IME_CONVERT, VK_CONVERT },
412 { GATE_KBD_KEY_START_LEFT, VK_LWIN },
413 { GATE_KBD_KEY_START_RIGHT, VK_RWIN },
414 { GATE_KBD_KEY_APPS, VK_APPS },
415 { GATE_KBD_KEY_SHIFT_LEFT, VK_LSHIFT },
416 { GATE_KBD_KEY_SHIFT_RIGHT, VK_RSHIFT },
417 { GATE_KBD_KEY_CTRL_LEFT, VK_LCONTROL },
418 { GATE_KBD_KEY_CTRL_RIGHT, VK_RCONTROL },
419 { GATE_KBD_KEY_MENU_LEFT, VK_LMENU },
420 { GATE_KBD_KEY_MENU_RIGHT, VK_RMENU },
421 { GATE_KBD_KEY_IME_PROCESS, VK_PROCESSKEY },
422 { GATE_KBD_KEY_ATTN, VK_ATTN },
423 { GATE_KBD_KEY_CRSEL, VK_CRSEL },
424 { GATE_KBD_KEY_EXSEL, VK_EXSEL },
425 { GATE_KBD_KEY_ERASE_EOF, VK_EREOF },
426 #endif
427 #ifdef VK_NONCONVERT
428 { GATE_KBD_KEY_IME_NONCONVERT, VK_NONCONVERT },
429 #endif
430 #ifdef VK_ACCEPT
431 { GATE_KBD_KEY_IME_ACCEPT, VK_ACCEPT },
432 #endif
433 #ifdef VK_MODECHANGE
434 { GATE_KBD_KEY_IME_MODECHANGE, VK_MODECHANGE },
435 #endif
436 { GATE_KBD_KEY_SPACEBAR, VK_SPACE },
437 { GATE_KBD_KEY_PGUP, VK_PRIOR },
438 { GATE_KBD_KEY_PGDOWN, VK_NEXT },
439 { GATE_KBD_KEY_END, VK_END },
440 { GATE_KBD_KEY_HOME, VK_HOME },
441 { GATE_KBD_KEY_LEFT, VK_LEFT },
442 { GATE_KBD_KEY_UP, VK_UP },
443 { GATE_KBD_KEY_RIGHT, VK_RIGHT },
444 { GATE_KBD_KEY_DOWN, VK_DOWN },
445 { GATE_KBD_KEY_SELECT, VK_SELECT },
446 { GATE_KBD_KEY_PRINT, VK_PRINT },
447 { GATE_KBD_KEY_EXECUTE, VK_EXECUTE },
448 { GATE_KBD_KEY_PRINTSCREEN, VK_SNAPSHOT },
449 { GATE_KBD_KEY_INSERT, VK_INSERT },
450 { GATE_KBD_KEY_DELETE, VK_DELETE },
451 { GATE_KBD_KEY_HELP, VK_HELP },
452 { GATE_KBD_KEY_0, 0x30 },
453 { GATE_KBD_KEY_1, 0x31 },
454 { GATE_KBD_KEY_2, 0x32 },
455 { GATE_KBD_KEY_3, 0x33 },
456 { GATE_KBD_KEY_4, 0x34 },
457 { GATE_KBD_KEY_5, 0x35 },
458 { GATE_KBD_KEY_6, 0x36 },
459 { GATE_KBD_KEY_7, 0x37 },
460 { GATE_KBD_KEY_8, 0x38 },
461 { GATE_KBD_KEY_9, 0x39 },
462 { GATE_KBD_KEY_A, 0x41 },
463 { GATE_KBD_KEY_B, 0x42 },
464 { GATE_KBD_KEY_C, 0x43 },
465 { GATE_KBD_KEY_D, 0x44 },
466 { GATE_KBD_KEY_E, 0x45 },
467 { GATE_KBD_KEY_F, 0x46 },
468 { GATE_KBD_KEY_G, 0x47 },
469 { GATE_KBD_KEY_H, 0x48 },
470 { GATE_KBD_KEY_I, 0x49 },
471 { GATE_KBD_KEY_J, 0x4a },
472 { GATE_KBD_KEY_K, 0x4b },
473 { GATE_KBD_KEY_L, 0x4c },
474 { GATE_KBD_KEY_M, 0x4d },
475 { GATE_KBD_KEY_N, 0x4e },
476 { GATE_KBD_KEY_O, 0x4f },
477 { GATE_KBD_KEY_P, 0x50 },
478 { GATE_KBD_KEY_Q, 0x51 },
479 { GATE_KBD_KEY_R, 0x52 },
480 { GATE_KBD_KEY_S, 0x53 },
481 { GATE_KBD_KEY_T, 0x54 },
482 { GATE_KBD_KEY_U, 0x55 },
483 { GATE_KBD_KEY_V, 0x56 },
484 { GATE_KBD_KEY_W, 0x57 },
485 { GATE_KBD_KEY_X, 0x58 },
486 { GATE_KBD_KEY_Y, 0x59 },
487 { GATE_KBD_KEY_Z, 0x5a },
488 { GATE_KBD_KEY_NUM0, VK_NUMPAD0 },
489 { GATE_KBD_KEY_NUM1, VK_NUMPAD1 },
490 { GATE_KBD_KEY_NUM2, VK_NUMPAD2 },
491 { GATE_KBD_KEY_NUM3, VK_NUMPAD3 },
492 { GATE_KBD_KEY_NUM4, VK_NUMPAD4 },
493 { GATE_KBD_KEY_NUM5, VK_NUMPAD5 },
494 { GATE_KBD_KEY_NUM6, VK_NUMPAD6 },
495 { GATE_KBD_KEY_NUM7, VK_NUMPAD7 },
496 { GATE_KBD_KEY_NUM8, VK_NUMPAD8 },
497 { GATE_KBD_KEY_NUM9, VK_NUMPAD9 },
498 { GATE_KBD_KEY_MULTIPLY, VK_MULTIPLY },
499 { GATE_KBD_KEY_ADD, VK_ADD },
500 { GATE_KBD_KEY_SEPARATOR, VK_SEPARATOR },
501 { GATE_KBD_KEY_SUBTRACT, VK_SUBTRACT },
502 { GATE_KBD_KEY_DECIMAL, VK_DECIMAL },
503 { GATE_KBD_KEY_DEVIDE, VK_DIVIDE },
504 { GATE_KBD_KEY_F1, VK_F1 },
505 { GATE_KBD_KEY_F2, VK_F2 },
506 { GATE_KBD_KEY_F3, VK_F3 },
507 { GATE_KBD_KEY_F4, VK_F4 },
508 { GATE_KBD_KEY_F5, VK_F5 },
509 { GATE_KBD_KEY_F6, VK_F6 },
510 { GATE_KBD_KEY_F7, VK_F7 },
511 { GATE_KBD_KEY_F8, VK_F8 },
512 { GATE_KBD_KEY_F9, VK_F9 },
513 { GATE_KBD_KEY_F10, VK_F10 },
514 { GATE_KBD_KEY_F11, VK_F11 },
515 { GATE_KBD_KEY_F12, VK_F12 },
516 { GATE_KBD_KEY_F13, VK_F13 },
517 { GATE_KBD_KEY_F14, VK_F14 },
518 { GATE_KBD_KEY_F15, VK_F15 },
519 { GATE_KBD_KEY_F16, VK_F16 },
520 { GATE_KBD_KEY_F17, VK_F17 },
521 { GATE_KBD_KEY_F18, VK_F18 },
522 { GATE_KBD_KEY_F19, VK_F19 },
523 { GATE_KBD_KEY_F20, VK_F20 },
524 { GATE_KBD_KEY_F21, VK_F21 },
525 { GATE_KBD_KEY_F22, VK_F22 },
526 { GATE_KBD_KEY_F23, VK_F23 },
527 { GATE_KBD_KEY_F24, VK_F24 },
528 { GATE_KBD_KEY_SCROLLLOCK, VK_SCROLL },
529 #if defined(VK_PLAY)
530 { GATE_KBD_KEY_PLAY, VK_PLAY },
531 #endif
532 #if defined(VK_ZOOM)
533 { GATE_KBD_KEY_ZOOM, VK_ZOOM },
534 #endif
535 #if defined(VK_OEM_1)
536 { GATE_KBD_KEY_QUOTE, VK_OEM_1 },
537 #endif
538 #if defined(VK_OEM_2)
539 { GATE_KBD_KEY_SLASH, VK_OEM_2 },
540 #endif
541 #if defined(VK_OEM_3)
542 { GATE_KBD_KEY_TILDE, VK_OEM_3 },
543 #endif
544 #if defined(VK_OEM_4)
545 { GATE_KBD_KEY_BRACE_LEFT, VK_OEM_4 },
546 #endif
547 #if defined(VK_OEM_5)
548 { GATE_KBD_KEY_BACKSLASH, VK_OEM_5 },
549 #endif
550 #if defined(VK_OEM_6)
551 { GATE_KBD_KEY_BRACE_RIGHT, VK_OEM_6 },
552 #endif
553 #if defined(VK_OEM_7)
554 { GATE_KBD_KEY_QUOTE, VK_OEM_7 },
555 #endif
556 #if defined(VK_SLEEP)
557 { GATE_KBD_KEY_SLEEP, VK_SLEEP },
558 #endif
559 #if !defined(GATE_COMPILER_MSVC98)
560 { GATE_KBD_KEY_BROWSER_BACK, VK_BROWSER_BACK },
561 { GATE_KBD_KEY_BROWSER_FORWARD, VK_BROWSER_FORWARD },
562 { GATE_KBD_KEY_BROWSER_REFRESH, VK_BROWSER_REFRESH },
563 { GATE_KBD_KEY_BROWSER_STOP, VK_BROWSER_STOP },
564 { GATE_KBD_KEY_BROWSER_SEARCH, VK_BROWSER_SEARCH },
565 { GATE_KBD_KEY_BROWSER_FAVORITES, VK_BROWSER_FAVORITES },
566 { GATE_KBD_KEY_BROWSER_HOME, VK_BROWSER_HOME },
567 { GATE_KBD_KEY_VOLUME_MUTE, VK_VOLUME_MUTE },
568 { GATE_KBD_KEY_VOLUME_DOWN, VK_VOLUME_DOWN },
569 { GATE_KBD_KEY_VOLUME_UP, VK_VOLUME_UP },
570 { GATE_KBD_KEY_MEDIA_NEXT, VK_MEDIA_NEXT_TRACK },
571 { GATE_KBD_KEY_MEDIA_PREVIOUS, VK_MEDIA_PREV_TRACK },
572 { GATE_KBD_KEY_MEDIA_STOP, VK_MEDIA_STOP },
573 { GATE_KBD_KEY_MEDIA_PLAY, VK_MEDIA_PLAY_PAUSE },
574 { GATE_KBD_KEY_LAUNCH_MAIL, VK_LAUNCH_MAIL },
575 { GATE_KBD_KEY_LAUNCH_MEDIA, VK_LAUNCH_MEDIA_SELECT },
576 { GATE_KBD_KEY_LAUNCH_APP, VK_LAUNCH_APP1 },
577 { GATE_KBD_KEY_LAUNCH_APP2, VK_LAUNCH_APP2 },
578 #if defined(VK_OEM_NEC_EQUAL)
579 { GATE_KBD_KEY_EQUAL, VK_OEM_NEC_EQUAL },
580 #endif
581 #endif
582 { GATE_KBD_KEY_NUMLOCK, VK_NUMLOCK }
583 };
584
585 static gate_size_t const win32_global_vkey_mappings_count = sizeof(win32_global_vkey_mappings) / sizeof(win32_global_vkey_mappings[0]);
586
587
588 gate_result_t gate_keyboard_parse_native_key(gate_input_nativekeycode_t native_key,
589 gate_input_keycode_t* gate_key,
590 gate_input_keystates_t* gate_kbdstate)
591 {
592 /* native_key == (VKEY & 0xffffffff) */
593 gate_size_t index;
594
595 for (index = 0; index != win32_global_vkey_mappings_count; ++index)
596 {
597 if (win32_global_vkey_mappings[index].native_code == native_key)
598 {
599 if (gate_key)
600 {
601 *gate_key = win32_global_vkey_mappings[index].gate_code;
602 }
603 if (gate_kbdstate)
604 {
605 #if !defined(GATE_SYS_WINSTORE) && !defined(GATE_SYS_WIN16)
606 gate_win32_userapi_t* userapi = gate_win32_userapi();
607 *gate_kbdstate = 0;
608 if (userapi->UserGetKeyState)
609 {
610 if (userapi->UserGetKeyState(VK_CONTROL) & 0x8000)
611 {
612 *gate_kbdstate |= GATE_KBD_KEYSTATE_CTRL;
613 }
614 if (userapi->UserGetKeyState(VK_SHIFT) & 0x8000)
615 {
616 *gate_kbdstate |= GATE_KBD_KEYSTATE_SHIFT;
617 }
618 if (userapi->UserGetKeyState(VK_MENU) & 0x8000)
619 {
620 *gate_kbdstate |= GATE_KBD_KEYSTATE_MENU;
621 }
622 }
623 #else
624 * gate_kbdstate = 0;
625 #endif
626 }
627 return GATE_RESULT_OK;
628 }
629 }
630 return GATE_RESULT_NOMATCH;
631 }
632
633 gate_result_t gate_keyboard_build_native_key(gate_input_keycode_t gate_key, gate_input_keystates_t gate_kbdstate, gate_input_nativekeycode_t* native_key)
634 {
635 gate_size_t index;
636
637 GATE_UNUSED_ARG(gate_kbdstate);
638
639 for (index = 0; index != win32_global_vkey_mappings_count; ++index)
640 {
641 if (win32_global_vkey_mappings[index].gate_code == gate_key)
642 {
643 if (native_key)
644 {
645 *native_key = win32_global_vkey_mappings[index].native_code;
646 }
647 return GATE_RESULT_OK;
648 }
649 }
650 return GATE_RESULT_NOMATCH;
651 }
652
653
654 struct gate_console_char_map
655 {
656 WORD vkey;
657 gate_char32_t chr;
658 };
659
660 static struct gate_console_char_map const special_vkey_mappings[] = {
661 { VK_BACK, 0x232B },
662 { VK_TAB, 0x21E5 },
663 { VK_CLEAR, 0x239A },
664 { VK_RETURN, 0x21A9 },
665 { VK_PAUSE, 0x2389 },
666 //{ VK_CAPITAL },
667 //{ VK_KANA },
668 //{ VK_JUNJA },
669 //{ VK_FINAL },
670 //{ VK_KANJI },
671 { VK_ESCAPE, 0x238B },
672 //{ VK_CONVERT },
673 #ifdef VK_NONCONVERT
674 //{ VK_NONCONVERT },
675 #endif
676 #ifdef VK_ACCEPT
677 //{ VK_ACCEPT },
678 #endif
679 #ifdef VK_MODECHANGE
680 //{ VK_MODECHANGE },
681 #endif
682 { VK_SPACE },
683 { VK_PRIOR, 0x21DE },
684 { VK_NEXT, 0x21DF },
685 { VK_END, 0x2198 },
686 { VK_HOME, 0x2196 },
687 { VK_LEFT, 0x2190 },
688 { VK_UP, 0x2191 },
689 { VK_RIGHT, 0x2192 },
690 { VK_DOWN, 0x2193 },
691 //{ GATE_KBD_KEY_SELECT, VK_SELECT },
692 { VK_PRINT, 0x2399 },
693 //{ GATE_KBD_KEY_EXECUTE, VK_EXECUTE },
694 { VK_SNAPSHOT, 0x2399 },
695 { VK_INSERT, 0x2380 },
696 { VK_DELETE, 0x2326 },
697 { VK_HELP, 0x2370 },
698 //{ GATE_KBD_KEY_APPS, VK_APPS },
699 { VK_MULTIPLY, 0x2715 },
700 { VK_ADD, 0x2795 },
701 //{ GATE_KBD_KEY_SEPARATOR, VK_SEPARATOR },
702 { VK_SUBTRACT, 0x2212 },
703 //{ GATE_KBD_KEY_DECIMAL, VK_DECIMAL },
704 { VK_DIVIDE, 0x2215 },
705 { VK_F1, 0x1F0B1 },
706 { VK_F2, 0x1F0B2 },
707 { VK_F3, 0x1F0B3 },
708 { VK_F4, 0x1F0B4 },
709 { VK_F5, 0x1F0B5 },
710 { VK_F6, 0x1F0B6 },
711 { VK_F7, 0x1F0B7 },
712 { VK_F8, 0x1F0B8 },
713 { VK_F9, 0x1F0B9 },
714 { VK_F10, 0x1F0BA },
715 { VK_SCROLL, 0x2913 },
716 //{ GATE_KBD_KEY_IME_PROCESS, VK_PROCESSKEY },
717 //{ GATE_KBD_KEY_ATTN, VK_ATTN },
718 //{ GATE_KBD_KEY_CRSEL, VK_CRSEL },
719 //{ GATE_KBD_KEY_EXSEL, VK_EXSEL },
720 //{ GATE_KBD_KEY_ERASE_EOF, VK_EREOF },
721 #if defined(VK_LWIN)
722 { VK_LWIN, 0x2756 },
723 #endif
724 #if defined(VK_RWIN)
725 { VK_RWIN, 0x2756 },
726 #endif
727 #if defined(VK_PLAY)
728 { VK_PLAY, 0x25B6 },
729 #endif
730 #if defined(VK_ZOOM)
731 { VK_ZOOM, 0x2BD0 },
732 #endif
733 #if defined(VK_OEM_1)
734 { VK_OEM_1, ';' },
735 #endif
736 #if defined(VK_OEM_2)
737 { VK_OEM_2, '/', /*0x2215*/ }, /* slash */
738 #endif
739 #if defined(VK_OEM_5)
740 { VK_OEM_5, '\\' /*0x2216*/ }, /* backslash*/
741 #endif
742 #if defined(VK_OEM_4)
743 { VK_OEM_4, '{' },
744 #endif
745 #if defined(VK_OEM_6)
746 { VK_OEM_6, '}' },
747 #endif
748 #if defined(VK_OEM_7)
749 { VK_OEM_7, '\'' },
750 #endif
751 #if defined(VK_OEM_3)
752 { VK_OEM_3, '~' },
753 #endif
754 #if defined(VK_OEM_102)
755 { VK_OEM_102, '\\' },
756 #endif
757 #if defined(VK_SLEEP)
758 { VK_SLEEP, 0x21E8 },
759 #endif
760 #if !defined(GATE_COMPILER_MSVC98)
761 //{ VK_BROWSER_BACK, 0x21E6 },
762 //{ VK_BROWSER_FORWARD, 0x21E8 },
763 //{ VK_BROWSER_REFRESH, 0x27F2 },
764 //{ VK_BROWSER_STOP, 0x2327 },
765 //{ VK_BROWSER_SEARCH, 0x1F50D },
766 //{ VK_BROWSER_FAVORITES, 0x1F3E1 },
767 //{ VK_BROWSER_HOME, 0x1F3E0 },
768 //{ VK_VOLUME_MUTE, 0x1F507 },
769 //{ VK_VOLUME_DOWN, 0x1F509 },
770 //{ VK_VOLUME_UP, 0x1F50A },
771 //{ VK_MEDIA_NEXT_TRACK, 0x23ED },
772 //{ VK_MEDIA_PREV_TRACK, 0x23EE },
773 //{ VK_MEDIA_STOP, 0x25FC },
774 //{ VK_MEDIA_PLAY_PAUSE, 0x23EF },
775 //{ VK_LAUNCH_MAIL, 0x2709 },
776 //{ VK_LAUNCH_MEDIA_SELECT, 0x1F508 },
777 #endif
778 { '0', '0' },
779 { '1', '1' },
780 { '2', '2' },
781 { '3', '3' },
782 { '4', '4' },
783 { '5', '5' },
784 { '6', '6' },
785 { '7', '7' },
786 { '8', '8' },
787 { '9', '9' },
788
789 { 'A', 'A' },
790 { 'B', 'B' },
791 { 'C', 'C' },
792 { 'D', 'D' },
793 { 'E', 'E' },
794 { 'F', 'F' },
795 { 'G', 'G' },
796 { 'H', 'H' },
797 { 'I', 'I' },
798 { 'J', 'J' },
799 { 'K', 'K' },
800 { 'L', 'L' },
801 { 'M', 'M' },
802 { 'N', 'N' },
803 { 'O', 'O' },
804 { 'P', 'P' },
805 { 'Q', 'Q' },
806 { 'R', 'R' },
807 { 'S', 'S' },
808 { 'T', 'T' },
809 { 'U', 'U' },
810 { 'V', 'V' },
811 { 'W', 'W' },
812 { 'X', 'X' },
813 { 'Y', 'Y' },
814 { 'Z', 'Z' },
815
816 { 'A', 'a' },
817 { 'B', 'b' },
818 { 'C', 'c' },
819 { 'D', 'd' },
820 { 'E', 'e' },
821 { 'F', 'f' },
822 { 'G', 'g' },
823 { 'H', 'h' },
824 { 'I', 'i' },
825 { 'J', 'j' },
826 { 'K', 'k' },
827 { 'L', 'l' },
828 { 'M', 'm' },
829 { 'N', 'n' },
830 { 'O', 'o' },
831 { 'P', 'p' },
832 { 'Q', 'q' },
833 { 'R', 'r' },
834 { 'S', 's' },
835 { 'T', 't' },
836 { 'U', 'u' },
837 { 'V', 'v' },
838 { 'W', 'w' },
839 { 'X', 'x' },
840 { 'Y', 'y' },
841 { 'Z', 'z' },
842
843 #if defined(VK_OEM_PLUS)
844 { VK_OEM_PLUS, '+' },
845 #endif
846 #if defined(VK_OEM_COMMA)
847 { VK_OEM_COMMA, ',' },
848 #endif
849 #if defined(VK_OEM_MINUS)
850 { VK_OEM_MINUS, '-' },
851 #endif
852 #if defined(VK_OEM_PERIOD)
853 { VK_OEM_PERIOD, '.' },
854 #endif
855
856 { VK_NUMLOCK, 0x21ED },
857 { VK_NUMPAD0, '0' },
858 { VK_NUMPAD1, '1' },
859 { VK_NUMPAD2, '2' },
860 { VK_NUMPAD3, '3' },
861 { VK_NUMPAD4, '4' },
862 { VK_NUMPAD5, '5' },
863 { VK_NUMPAD6, '6' },
864 { VK_NUMPAD7, '7' },
865 { VK_NUMPAD8, '8' },
866 { VK_NUMPAD9, '9' }
867 };
868
869 static gate_size_t const special_vkey_mappings_count = sizeof(special_vkey_mappings) / sizeof(special_vkey_mappings[0]);
870
871
872 gate_result_t gate_keyboard_native_key_to_unicode(gate_input_nativekeycode_t native_key, gate_char32_t* ptr_chr)
873 {
874 gate_size_t ndx;
875 for (ndx = 0; ndx != special_vkey_mappings_count; ++ndx)
876 {
877 if (native_key == special_vkey_mappings[ndx].vkey)
878 {
879 *ptr_chr = special_vkey_mappings[ndx].chr;
880 return GATE_RESULT_OK;
881 }
882 }
883 return GATE_RESULT_NOMATCH;
884 }
885
886 gate_result_t gate_keyboard_unicode_to_native_key(gate_char32_t chr, gate_input_nativekeycode_t* ptr_native_key)
887 {
888 gate_size_t ndx;
889 for (ndx = 0; ndx != special_vkey_mappings_count; ++ndx)
890 {
891 if (chr == special_vkey_mappings[ndx].chr)
892 {
893 *ptr_native_key = special_vkey_mappings[ndx].vkey;
894 return GATE_RESULT_OK;
895 }
896 }
897 return GATE_RESULT_NOMATCH;
898 }
899
900
901 #endif /* GATE_SYS_WIN */
902
903
904 #if defined(GATE_INPUT_POSIX_IMPL)
905
906
907 1 gate_result_t gate_keyboard_parse_native_key(gate_input_keycode_t native_key,
908 gate_input_keycode_t* gate_key, gate_input_keystates_t* gate_kbdstate)
909 {
910 1 gate_uint64_t k = (gate_uint64_t)(gate_uintptr_t)native_key;
911 gate_uint8_t items[sizeof(gate_input_keycode_t)];
912 1 gate_size_t item_count = 0;
913 gate_uint8_t item;
914 1 gate_uint8_t* ptr = &items[sizeof(gate_input_keycode_t) - 1];
915 gate_size_t cnt;
916
917 for (;;)
918 {
919 3 item = (gate_uint8_t)(k & 0xff);
920 2 k >>= 8;
921
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (item == 0)
922 {
923 1 break;
924 }
925 1 ++item_count;
926 1 ptr = &items[sizeof(items) - item_count];
927 1 *ptr = item;
928 }
929
930 1 cnt = gate_keyboard_parse_vt100_symbols((char*)ptr, item_count, gate_key, gate_kbdstate, NULL);
931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (cnt == 0)
932 {
933 return GATE_RESULT_FAILED;
934 }
935 else
936 {
937 1 return GATE_RESULT_OK;
938 }
939 }
940 1 gate_result_t gate_keyboard_build_native_key(gate_input_keycode_t gate_key, gate_input_keystates_t gate_kbdstate,
941 gate_input_nativekeycode_t* native_key)
942 {
943 1 gate_result_t ret = GATE_RESULT_FAILED;
944 1 gate_input_nativekeycode_t nkey = 0;
945 char symbols[sizeof(gate_input_keycode_t)];
946 gate_size_t used, index;
947 do
948 {
949 1 used = gate_keyboard_build_vt100_symbols(gate_key, gate_kbdstate, symbols, sizeof(symbols));
950
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (index = 0; index != used; ++index)
951 {
952 1 nkey <<= 8;
953 1 nkey |= (gate_input_keycode_t)(gate_uint8_t)symbols[index];
954 }
955
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (native_key)
956 {
957 1 *native_key = nkey;
958 }
959 1 ret = GATE_RESULT_OK;
960 } while (0);
961
962 1 return ret;
963 }
964
965
966 #endif /* GATE_SYS_POSIX */
967
968
969 #if defined(GATE_INPUT_NO_IMPL)
970
971
972 gate_result_t gate_keyboard_parse_native_key(gate_input_keycode_t native_key,
973 gate_input_keycode_t* gate_key, gate_input_keystates_t* gate_kbdstate)
974 {
975 return GATE_RESULT_NOTIMPLEMENTED;
976 }
977 gate_result_t gate_keyboard_build_native_key(gate_input_keycode_t gate_key, gate_input_keystates_t gate_kbdstate,
978 gate_input_nativekeycode_t* native_key)
979 {
980 return GATE_RESULT_NOTIMPLEMENTED;
981 }
982
983
984 #endif /* GATE_INPUT_NO_IMPL */
985