YSTest: Keys.cpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
Keys.cpp
浏览该文件的文档.
1 /*
2 © 2009-2014 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "YCLib/YModules.h"
29 #include YFM_YCLib_Keys
30 #include YFM_YCLib_NativeAPI
31
32 namespace platform
33 {
34
35 KeyIndex
36 FindFirstKey(const KeyInput& keys) ynothrow
37 {
38 #if _GLIBCXX_BITSET
39 return keys._Find_first();
40 #else
41 # error "Only libstdc++ is currently supported."
42 #endif
43 }
44
45 KeyIndex
46 FindNextKey(const KeyInput& keys, KeyIndex key) ynothrow
47 {
48 #if _GLIBCXX_BITSET
49 return keys._Find_next(key);
50 #else
51 # error "Only libstdc++ is currently supported."
52 #endif
53 }
54
55
56 namespace KeyCategory
57 {
58
60 namespace
61 {
62
63 #if YCL_DS
64 yconstexpr Category KeyCategoryTable[KeyBitsetWidth]{
65 Editing, // KEY_A as a synonym of 'Enter'.
66 Navigation, // KEY_B as a synonym of 'Esc'.
67 Menu | System, // KEY_SELECT as a synonym of 'Menu'.
68 Editing | Menu | System, // KEY_START as a synonym of 'Enter'.
69 Navigation, // KEY_RIGHT is an arrow key.
70 Navigation, // KEY_LEFT is an arrow key.
71 Navigation, // KEY_UP is an arrow key.
72 Navigation, // KEY_DOWN is an arrow key.
73 Navigation, // KEY_R is an extended navigation key.
74 Navigation, // KEY_L is an extended navigation key.
75 Navigation, // KEY_X is an extended navigation key.
76 Navigation, // KEY_Y is an extended navigation key.
77 NonKeyboard, // KEY_TOUCH is a key of cursor device.
78 NonKeyboard, // KEY_LID is a key of lid.
79 Editing | Virtual, // Backapce is an editing key.
80 Editing | Virtual, // Tab is an editing key.
81 Modifier | Virtual, // Shift is an modifier key.
82 Modifier | Virtual, // Ctrl is an modifier key.
83 Modifier | Menu | Virtual, // Alt is an modifier menu key.
84 System | Virtual, // Pause is a system key.
85 Lock | Virtual, // CapsLock is an lock key.
86 Editing | Virtual, // Insert is an editing key.
87 Editing | Virtual, // Delete is an editing key.
88 Editing | NonKeyboard, // Extended secondary key.
89 Editing | NonKeyboard // Extended tertiary key.
90 };
91 #elif YCL_Win32
92 // See http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx .
93 yconstexpr const Category KeyCategoryTable[KeyBitsetWidth]{
94 None, // 0 is not assigned.
95 Editing | NonKeyboard, // VK_LBUTTON is a mouse key.
96 Editing | NonKeyboard, // VK_RBUTTON is a mouse key.
97 System | Composed, // VK_CANCEL.
98 Editing | NonKeyboard, // VK_MBUTTON is a mouse key.
99 NonKeyboard, // VK_XBUTTON1 is a mouse key.
100 NonKeyboard, // VK_XBUTTON2 is a mouse key.
101 None, // Undefined.
102 Editing, // VK_BACK.
103 Editing, // VK_TAB.
104 None, // Reserved.
105 None, // Reserved.
106 Editing, // VK_CLEAR.
107 Editing, // VK_RETURN.
108 None, // Undefined.
109 None, // Undefined.
110 Modifier | Composed, // VK_SHIFT.
111 Modifier | Composed, // VK_CONTROL.
112 Modifier | Menu | Composed, // VK_MENU is a composed menu modifier key.
113 System, // VK_PAUSE.
114 Lock, // VK_CAPITAL.
115 IME, // VK_KANA, VK_HANGUEL, VK_HANGUL.
116 None, // Undefined.
117 IME, // VK_JUNJA.
118 IME, // VK_FINAL.
119 IME, // VK_HANJA, VK_KANJI.
120 None, // Undefined.
121 Navigation, // VK_ESCAPE.
122 IME, // VK_CONVERT.
123 IME, // VK_NONCONVERT.
124 IME, // VK_ACCEPT.
125 IME, // VK_MODECHANGE.
126 Editing, // VK_SPACE.
127 Navigation, // VK_PRIOR.
128 Navigation, // VK_NEXT.
129 Navigation, // VK_END.
130 Navigation, // VK_HOME.
131 Navigation, // VK_LEFT.
132 Navigation, // VK_UP.
133 Navigation, // VK_RIGHT.
134 Navigation, // VK_DOWN.
135 System, // VK_SELECT.
136 System, // VK_PRINT.
137 System, // VK_EXECUTE.
138 System, // VK_SNAPSHOT.
139 Editing, // VK_INSERT.
140 Editing, // VK_DELETE.
141 Function, // VK_HELP.
142 Numeric, // 0 key.
143 Numeric,
144 Numeric,
145 Numeric,
146 Numeric,
147 Numeric,
148 Numeric,
149 Numeric,
150 Numeric,
151 Numeric, // 9 key.
152 None, // Undefined.
153 None, // Undefined.
154 None, // Undefined.
155 None, // Undefined.
156 None, // Undefined.
157 None, // Undefined.
158 None, // Undefined.
159 Alphabetic, // A key.
160 Alphabetic,
161 Alphabetic,
162 Alphabetic,
163 Alphabetic,
164 Alphabetic,
165 Alphabetic,
166 Alphabetic,
167 Alphabetic,
168 Alphabetic,
169 Alphabetic,
170 Alphabetic,
171 Alphabetic,
172 Alphabetic,
173 Alphabetic,
174 Alphabetic,
175 Alphabetic,
176 Alphabetic,
177 Alphabetic,
178 Alphabetic,
179 Alphabetic,
180 Alphabetic,
181 Alphabetic,
182 Alphabetic,
183 Alphabetic,
184 Alphabetic, // Z key.
185 Modifier | Menu, // VK_LWIN.
186 Modifier | Menu, // VK_RWIN.
187 Function | Menu, // VK_APPS.
188 None, // Reserved.
189 System, // VK_SLEEP.
190 Numeric | Keypad, // VK_NUMPAD0.
191 Numeric | Keypad,
192 Numeric | Keypad,
193 Numeric | Keypad,
194 Numeric | Keypad,
195 Numeric | Keypad,
196 Numeric | Keypad,
197 Numeric | Keypad,
198 Numeric | Keypad,
199 Numeric | Keypad, // VK_NUMPAD9.
200 Punctuation | Keypad, // VK_ADD.
201 Punctuation | Keypad, // VK_MULTIPLY.
202 Punctuation | Keypad, // VK_SEPARATOR.
203 Punctuation | Keypad, // VK_SUBTRACT.
204 Punctuation | Keypad, // VK_DECIMAL.
205 Punctuation | Keypad, // VK_DIVIDE.
206 Function, // VK_F1.
207 Function,
208 Function,
209 Function,
210 Function,
211 Function,
212 Function,
213 Function,
214 Function,
215 Function,
216 Function,
217 Function, // VK_F12.
218 Function,
219 Function,
220 Function,
221 Function,
222 Function,
223 Function,
224 Function,
225 Function,
226 Function,
227 Function,
228 Function,
229 Function, // VK_F24.
230 None, // Unassigned.
231 None, // Unassigned.
232 None, // Unassigned.
233 None, // Unassigned.
234 None, // Unassigned.
235 None, // Unassigned.
236 None, // Unassigned.
237 None, // Unassigned.
238 Lock, // VK_NUMLOCK.
239 Lock, // VK_SCROLL.
240 OEM,
241 OEM,
242 OEM,
243 OEM,
244 OEM,
245 None, // Unassigned.
246 None, // Unassigned.
247 None, // Unassigned.
248 None, // Unassigned.
249 None, // Unassigned.
250 None, // Unassigned.
251 None, // Unassigned.
252 None, // Unassigned.
253 None, // Unassigned.
254 Modifier, // VK_LSHIFT.
255 Modifier, // VK_RSHIFT.
256 Modifier, // VK_LCONTROL.
257 Modifier, // VK_RCONTROL.
258 Modifier | Menu, // VK_LMENU.
259 Modifier | Menu, // VK_RMENU.
260 Function, // VK_BROWSER_BACK.
261 Function, // VK_BROWSER_FORWARD.
262 Function, // VK_BROWSER_REFRESH.
263 Function, // VK_BROWSER_STOP.
264 Function, // VK_BROWSER_SEARCH.
265 Function, // VK_BROWSER_FAVORITES.
266 Function, // VK_BROWSER_HOME.
267 Function, // VK_VOLUME_MUTE.
268 Function, // VK_VOLUME_DOWN.
269 Function, // VK_VOLUME_UP.
270 Function, // VK_MEDIA_NEXT_TRACK.
271 Function, // VK_MEDIA_PREV_TRACK.
272 Function, // VK_MEDIA_STOP.
273 Function, // VK_MEDIA_PLAY_PAUSE.
274 Function, // VK_LAUNCH_MAIL.
275 Function, // VK_LAUNCH_MEDIA_SELECT.
276 Function, // VK_LAUNCH_APP1.
277 Function, // VK_LAUNCH_APP2.
278 None, // Reserved.
279 None, // Reserved.
280 Punctuation | OEM, // VK_OEM_1.
281 Punctuation | OEM, // VK_OEM_PLUS.
282 Punctuation | OEM, // VK_OEM_COMMA.
283 Punctuation | OEM, // VK_OEM_MINUS.
284 Punctuation | OEM, // VK_OEM_PERIOD.
285 Punctuation | OEM, // VK_OEM_2.
286 Punctuation | OEM, // VK_OEM_3.
287 None, // Reserved.
288 None, // Reserved.
289 None, // Reserved.
290 None, // Reserved.
291 None, // Reserved.
292 None, // Reserved.
293 None, // Reserved.
294 None, // Reserved.
295 None, // Reserved.
296 None, // Reserved.
297 None, // Reserved.
298 None, // Reserved.
299 None, // Reserved.
300 None, // Reserved.
301 None, // Reserved.
302 None, // Reserved.
303 None, // Reserved.
304 None, // Reserved.
305 None, // Reserved.
306 None, // Reserved.
307 None, // Reserved.
308 None, // Reserved.
309 None, // Reserved.
310 None, // Unassigned.
311 None, // Unassigned.
312 None, // Unassigned.
313 Punctuation | OEM, // VK_OEM_4.
314 Punctuation | OEM, // VK_OEM_5.
315 Punctuation | OEM, // VK_OEM_6.
316 Punctuation | OEM, // VK_OEM_7.
317 OEM, // VK_OEM_8.
318 None, // Reserved.
319 OEM, // OEM specific.
320 Punctuation | OEM, // VK_OEM_102.
321 OEM, // OEM specific.
322 OEM, // OEM specific.
323 IME, // VK_PROCESSKEY.
324 OEM, // OEM specific.
325 Virtual, // VK_PACKET.
326 None, // Unassigned.
327 OEM, // OEM specific.
328 OEM, // OEM specific.
329 OEM, // OEM specific.
330 OEM, // OEM specific.
331 OEM, // OEM specific.
332 OEM, // OEM specific.
333 OEM, // OEM specific.
334 OEM, // OEM specific.
335 OEM, // OEM specific.
336 OEM, // OEM specific.
337 OEM, // OEM specific.
338 OEM, // OEM specific.
339 OEM, // OEM specific.
340 Function, // VK_ATTN.
341 Function, // VK_CRSEL.
342 Function, // VK_EXSEL.
343 Function, // VK_EREOF.
344 Function, // VK_PLAY.
345 Function, // VK_ZOOM.
346 None, // VK_NONAME.
347 None, // VK_PA1.
348 OEM | Function // VK_OEM_CLEAR.
349 };
350 #elif YCL_Android
351 // See http://developer.android.com/reference/android/view/KeyEvent.html .
352 yconstexpr const Category KeyCategoryTable[KeyBitsetWidth]{
353 None, // KEYCODE_UNKNOWN.
354 Function, // KEYCODE_SOFT_LEFT.
355 Function, // KEYCODE_SOFT_RIGHT .
356 System, // KEYCODE_HOME is handled by the framework.
357 Navigation, // KEYCODE_BACK.
358 Function, // KEYCODE_CALL.
359 Function, // KEYCODE_ENDCALL.
360 Numeric, // 0 key.
361 Numeric,
362 Numeric,
363 Numeric,
364 Numeric,
365 Numeric,
366 Numeric,
367 Numeric,
368 Numeric,
369 Numeric, // 9 key.
370 Punctuation, // KEYCODE_STAR.
371 Punctuation, // KEYCODE_POUND.
372 Navigation | Keypad, // KEYCODE_DPAD_UP.
373 Navigation | Keypad, // KEYCODE_DPAD_DOWN.
374 Navigation | Keypad, // KEYCODE_DPAD_LEFT.
375 Navigation | Keypad, // KEYCODE_DPAD_RIGHT.
376 Navigation | Keypad, // KEYCODE_DPAD_CENTER.
377 Function, // KEYCODE_VOLUME_UP.
378 Function, // KEYCODE_VOLUME_DOWN.
379 System, // KEYCODE_POWER.
380 Function, // KEYCODE_CAMERA.
381 Editing, // KEYCODE_CLEAR.
382 Alphabetic, // A key.
383 Alphabetic,
384 Alphabetic,
385 Alphabetic,
386 Alphabetic,
387 Alphabetic,
388 Alphabetic,
389 Alphabetic,
390 Alphabetic,
391 Alphabetic,
392 Alphabetic,
393 Alphabetic,
394 Alphabetic,
395 Alphabetic,
396 Alphabetic,
397 Alphabetic,
398 Alphabetic,
399 Alphabetic,
400 Alphabetic,
401 Alphabetic,
402 Alphabetic,
403 Alphabetic,
404 Alphabetic,
405 Alphabetic,
406 Alphabetic,
407 Alphabetic, // Z key.
408 Punctuation, // KEYCODE_COMMA.
409 Punctuation, // KEYCODE_PERIOD.
410 Modifier | Menu, // KEYCODE_ALT_LEFT.
411 Modifier | Menu, // KEYCODE_ALT_RIGHT.
412 Modifier, // KEYCODE_SHIFT_LEFT.
413 Modifier, // KEYCODE_SHIFT_RIGHT.
414 Editing, // KEYCODE_TAB.
415 Editing, // KEYCODE_SPACE.
416 Modifier, // KEYCODE_SYM.
417 Function, // KEYCODE_EXPLORER.
418 Function, // KEYCODE_ENVELOPE.
419 Editing, // KEYCODE_ENTER.
420 Editing, // KEYCODE_DEL.
421 Punctuation, // KEYCODE_GRAVE.
422 Punctuation, // KEYCODE_MINUS.
423 Punctuation, // KEYCODE_EQUALS.
424 Punctuation, // KEYCODE_LEFT_BRACKET.
425 Punctuation, // KEYCODE_RIGHT_BRACKET.
426 Punctuation, // KEYCODE_BACKSLASH.
427 Punctuation, // KEYCODE_SEMICOLON.
428 Punctuation, // KEYCODE_APOSTROPHE.
429 Punctuation, // KEYCODE_SLASH.
430 Punctuation, // KEYCODE_AT.
431 Modifier, // KEYCODE_NUM.
432 NonKeyboard, // KEYCODE_HEADSETHOOK.
433 Function, // KEYCODE_FOCUS.
434 Punctuation, // KEYCODE_PLUS.
435 Function | Menu, // KEYCODE_MENU.
436 Function, // KEYCODE_NOTIFICATION.
437 Function, // KEYCODE_SEARCH.
438 Function, // KEYCODE_MEDIA_PLAY_PAUSE.
439 Function, // KEYCODE_MEDIA_STOP.
440 Function, // KEYCODE_MEDIA_NEXT.
441 Function, // KEYCODE_MEDIA_PREVIOUS.
442 Function, // KEYCODE_MEDIA_REWIND.
443 Function, // KEYCODE_MEDIA_FAST_FORWARD.
444 Function, // KEYCODE_MUTE.
445 Navigation, // KEYCODE_PAGE_UP.
446 Navigation, // KEYCODE_PAGE_DOWN.
447 Modifier, // KEYCODE_PICTSYMBOLS.
448 IME | Modifier, // KEYCODE_SWITCH_CHARSET.
449 Function | Keypad, // KEYCODE_BUTTON_A.
450 Function | Keypad, // KEYCODE_BUTTON_B.
451 Function | Keypad, // KEYCODE_BUTTON_C.
452 Function | Keypad, // KEYCODE_BUTTON_X.
453 Function | Keypad, // KEYCODE_BUTTON_Y.
454 Function | Keypad, // KEYCODE_BUTTON_Z.
455 Function | Keypad, // KEYCODE_BUTTON_L1.
456 Function | Keypad, // KEYCODE_BUTTON_R1.
457 Function | Keypad, // KEYCODE_BUTTON_L2.
458 Function | Keypad, // KEYCODE_BUTTON_R2.
459 Function | Keypad, // KEYCODE_BUTTON_THUMBL.
460 Function | Keypad, // KEYCODE_BUTTON_THUMBR.
461 Function | Keypad, // KEYCODE_BUTTON_START.
462 Function | Keypad, // KEYCODE_BUTTON_SELECT.
463 Function | Keypad, // KEYCODE_BUTTON_MODE.
464 Navigation, // KEYCODE_ESCAPE.
465 Editing, // KEYCODE_FORWARD_DEL.
466 Modifier, // KEYCODE_CTRL_LEFT.
467 Modifier, // KEYCODE_CTRL_RIGHT.
468 Lock, // KEYCODE_CAPS_LOCK.
469 Lock, // KEYCODE_SCROLL_LOCK.
470 Modifier, // KEYCODE_META_LEFT.
471 Modifier, // KEYCODE_META_RIGHT.
472 Function | Modifier, // KEYCODE_FUNCTION.
473 System, // KEYCODE_SYSRQ.
474 System, // KEYCODE_BREAK.
475 Navigation, // KEYCODE_MOVE_HOME.
476 Navigation, // KEYCODE_MOVE_END.
477 Editing, // Editing.
478 Navigation, // KEYCODE_FORWARD.
479 Function, // KEYCODE_MEDIA_PLAY.
480 Function, // KEYCODE_MEDIA_PAUSE.
481 Function, // KEYCODE_MEDIA_CLOSE.
482 Function, // KEYCODE_MEDIA_EJECT.
483 Function, // KEYCODE_MEDIA_RECORD.
484 Function, // KEYCODE_F1.
485 Function,
486 Function,
487 Function,
488 Function,
489 Function,
490 Function,
491 Function,
492 Function,
493 Function,
494 Function,
495 Function, // KEYCODE_F12.
496 Lock, // KEYCODE_NUM_LOCK.
497 Numeric | Keypad, // KEYCODE_NUMPAD_0.
498 Numeric | Keypad,
499 Numeric | Keypad,
500 Numeric | Keypad,
501 Numeric | Keypad,
502 Numeric | Keypad,
503 Numeric | Keypad,
504 Numeric | Keypad,
505 Numeric | Keypad,
506 Numeric | Keypad, // KEYCODE_NUMPAD_9.
507 Punctuation | Keypad, // KEYCODE_NUMPAD_DIVIDE.
508 Punctuation | Keypad, // KEYCODE_NUMPAD_MULTIPLY.
509 Punctuation | Keypad, // KEYCODE_NUMPAD_SUBTRACT.
510 Punctuation | Keypad, // KEYCODE_NUMPAD_ADD.
511 Punctuation | Keypad, // KEYCODE_NUMPAD_DOT.
512 Punctuation | Keypad, // KEYCODE_NUMPAD_COMMA.
513 Editing | Keypad, // KEYCODE_NUMPAD_ENTER.
514 Punctuation | Keypad, // KEYCODE_NUMPAD_EQUALS.
515 Punctuation | Keypad, // KEYCODE_NUMPAD_LEFT_PAREN.
516 Punctuation | Keypad, // KEYCODE_NUMPAD_RIGHT_PAREN.
517 Function, // KEYCODE_VOLUME_MUTE.
518 Function, // KEYCODE_INFO.
519 Function, // KEYCODE_CHANNEL_UP.
520 Function, // KEYCODE_CHANNEL_DOWN.
521 Function, // KEYCODE_ZOOM_IN.
522 Function, // KEYCODE_ZOOM_OUT.
523 Function, // KEYCODE_TV.
524 Function, // KEYCODE_WINDOW.
525 Function, // KEYCODE_GUIDE.
526 Function, // KEYCODE_DVR.
527 Function, // KEYCODE_BOOKMARK.
528 Function, // KEYCODE_CAPTIONS.
529 Function, // KEYCODE_SETTINGS.
530 System, // KEYCODE_TV_POWER.
531 Function, // KEYCODE_TV_INPUT.
532 System, // KEYCODE_STB_POWER.
533 Function, // KEYCODE_STB_INPUT.
534 System, // KEYCODE_AVR_POWER.
535 Function, // KEYCODE_AVR_INPUT.
536 Function, // KEYCODE_PROG_RED.
537 Function, // KEYCODE_PROG_GREEN.
538 Function, // KEYCODE_PROG_YELLOW.
539 Function, // KEYCODE_PROG_BLUE.
540 Function, // KEYCODE_APP_SWITCH.
541 Function | Keypad, // KEYCODE_BUTTON_1.
542 Function | Keypad,
543 Function | Keypad,
544 Function | Keypad,
545 Function | Keypad,
546 Function | Keypad,
547 Function | Keypad,
548 Function | Keypad,
549 Function | Keypad,
550 Function | Keypad,
551 Function | Keypad,
552 Function | Keypad,
553 Function | Keypad,
554 Function | Keypad,
555 Function | Keypad,
556 Function | Keypad, // KEYCODE_BUTTON_16.
557 IME, // KEYCODE_LANGUAGE_SWITCH.
558 Function, // KEYCODE_MANNER_MODE.
559 Function, // KEYCODE_3D_MODE.
560 Function, // KEYCODE_CONTACTS.
561 Function, // KEYCODE_CALENDAR.
562 Function, // KEYCODE_MUSIC.
563 Function, // KEYCODE_CALCULATOR.
564 IME, // KEYCODE_ZENKAKU_HANKAKU.
565 IME, // KEYCODE_EISU.
566 IME, // KEYCODE_MUHENKAN.
567 IME, // KEYCODE_HENKAN.
568 IME, // KEYCODE_KATAKANA_HIRAGANA.
569 Punctuation, // KEYCODE_YEN.
570 Punctuation, // KEYCODE_RO.
571 IME, // KEYCODE_KANA.
572 System, // KEYCODE_ASSIST is not delivered to applications.
573 Function, // KEYCODE_BRIGHTNESS_DOWN.
574 Function, // KEYCODE_BRIGHTNESS_UP.
575 Function, // KEYCODE_MEDIA_AUDIO_TRACK.
576 Editing | NonKeyboard, // Extended primary key.
577 Editing | NonKeyboard, // Extended secondary key.
578 Editing | NonKeyboard // Extended tertiary key.
579 };
580 #else
581 # error "Unsupported platform found."
582 #endif
583
584 } // unnamed namespace;
585
586 Category
587 ClassifyKey(KeyIndex code) ynothrow
588 {
589 yconstraint(code < KeyBitsetWidth);
590 return KeyCategoryTable[code];
591 }
592
593 KeyIndex
594 FindFirstKeyInCategroy(const KeyInput& keys, KeyIndex cat) ynothrow
595 {
596 for(auto code(FindFirstKey(keys)); code != KeyBitsetWidth;
597 code = FindNextKey(keys, code))
598 if(ClassifyKey(code) & cat)
599 return code;
600 return KeyBitsetWidth;
601 }
602
603 } // namespace KeyCategory;
604
605
607 namespace
608 {
609
610 #if !YCL_DS
611 inline char
612 switch_key(char s) ynothrow
613 {
614 using namespace KeyCodes;
615
616 return std::isalpha(s) && FetchLockState(CapsLock) ? s ^ 0x20 : s;
617 }
618 #endif
619
620 } // unnamed namespace;
621
622 #if YCL_Win32
623 char
624 MapKeyChar(KeyIndex code) ynothrow
625 {
626 return ::MapVirtualKeyW(unsigned(code), MAPVK_VK_TO_CHAR) & 0x7F;
627 }
628 char
629 MapKeyChar(const KeyInput& keys, KeyIndex code) ynothrow
630 {
631 ystdex::byte state[256];
632 unsigned short s;
633
634 // NOTE: See implementation of %UpdateKeyStates.
635 for(std::size_t i(1); i < platform::KeyBitsetWidth - 1; ++i)
636 state[i] = keys[i] ? 0x80 : 0;
637 return ::ToAscii(code, ::MapVirtualKeyW(code, MAPVK_VK_TO_VSC), state, &s,
638 0) == 1 ? switch_key(char(s) & 0x7F) : char();
639 }
640
641 namespace KeyCodes
642 {
643
645 namespace
646 {
647
648 #if YCL_DS
649 bool caps_lock;
650 #endif
651
652 } // unnamed namespace;
653
654 bool
655 FetchLockState(KeyIndex code) ynothrow
656 {
657 #if YCL_DS || YCL_Android
658 return code == CapsLock ? caps_lock : false;
659 #elif YCL_Win32
660 return (::GetKeyState(code) & 0x0001) != 0;
661 #endif
662 }
663
664 void
665 ToggleLockState(KeyIndex code) ynothrow
666 {
667 #if YCL_DS || YCL_Android
668 if(code == CapsLock)
669 caps_lock = !caps_lock;
670 #elif YCL_Win32
671 if(KeyCategory::ClassifyKey(code) & KeyCategory::Lock)
672 {
673 ::INPUT input[2]{{INPUT_KEYBOARD, {}}, {INPUT_KEYBOARD, {}}};
674
675 yunseq(
676 input[0].ki.wVk = code, input[1].ki.wVk = code,
677 input[1].ki.dwFlags = KEYEVENTF_KEYUP
678 );
679 ::SendInput(2, input, sizeof(::INPUT));
680 }
681 #endif
682 }
683
684 }
685
686 #endif
687
688 }
689
platform::KeyCategory::Alphabetic
表示产生字母字符的键。
Definition: Keys.h:101
platform::KeyCategory::Composed
表示通过多个物理按键组合构成的键。
Definition: Keys.h:135
platform::KeyCategory::Function
表示功能键。
Definition: Keys.h:117
platform::MapKeyChar
yconstexpr MapKeyChar
Definition: Keys.h:190
platform::KeyIndex
std::size_t KeyIndex
按键索引类型：标识特定的按键在按键集合中的位置。
Definition: Keys.h:42
YModules.h
platform::KeyCategory::Keypad
表示小键盘键。
Definition: Keys.h:131
ystdex::byte
unsigned char byte
字节类型。
Definition: ydef.h:555
platform::KeyCategory::Editing
表示编辑键（如回车、空格、退格、插入、删除和制表符）
Definition: Keys.h:121
platform::KeyCategory::OEM
表示默认由设备制造商指定。
Definition: Keys.h:127
platform::KeyCategory::Modifier
表示修饰键。
Definition: Keys.h:115
platform::ynothrow
std::size_t size ynothrow
Definition: YCLib/FileSystem.h:256
YSLib::Drawing::size_t
size_t
Definition: ygdi.h:352
platform::KeyCategory::Category
Category
按键类别。
Definition: Keys.h:96
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
platform::KeyCategory::Numeric
表示产生数字字符的键。
Definition: Keys.h:103
platform::FindFirstKey
YF_API KeyIndex FindFirstKey(const KeyInput &) ynothrow
找到输入缓冲区记录中最小的按键编码。
Definition: Keys.cpp:36
platform::KeyCategory::Menu
表示菜单键（如 Menu 和 Win ）。
Definition: Keys.h:129
yconstraint
#define yconstraint
约束：接口语义。
Definition: cassert.h:47
platform::KeyCategory::ClassifyKey
Category ClassifyKey(KeyIndex code) ynothrow
Definition: Keys.cpp:587
platform::KeyCategory::Virtual
表示没有对应单一物理按键的虚拟键。
Definition: Keys.h:137
platform::KeyCategory::None
表示未分配或保留的键。
Definition: Keys.h:99
platform::KeyCategory::IME
表示输入法模式键（一般用于日文和韩文）。
Definition: Keys.h:125
platform::KeyCategory::Punctuation
表示产生标点字符的键。
Definition: Keys.h:107
platform_ex::Windows::s
return s
Definition: MinGW32.cpp:49
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
platform::KeyCategory::FindFirstKeyInCategroy
YF_API KeyIndex FindFirstKeyInCategroy(const KeyInput &, KeyIndex) ynothrow
找到第一个在指定类别的按键编码。
Definition: Keys.cpp:594
platform::FindNextKey
YF_API KeyIndex FindNextKey(const KeyInput &, KeyIndex) ynothrow
找到输入缓冲区记录中大于指定编码的最小的按键编码。
Definition: Keys.cpp:46
platform::KeyCategory::NonKeyboard
表示非键盘键（如鼠标键）。
Definition: Keys.h:133
platform::KeyCategory::Navigation
表示导航键（如方向键和 PgUp ）、菜单键和 Esc 。
Definition: Keys.h:119
platform::KeyCategory::Lock
表示锁定键。
Definition: Keys.h:113
platform::KeyInput
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。
Definition: Keys.h:68
platform::KeyCategory::System
表示系统键（如 SysRq/PrintScr 、 Break/Pause 和电源管理）。
Definition: Keys.h:123