GCC Code Coverage Report


Directory: src/gate/
File: src/gate/inputs.c
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 60 0.0%
Functions: 0 4 0.0%
Branches: 0 36 0.0%

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