YSTest: Keys.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

Keys.h
浏览该文件的文档.
1 /*
2 © 2011-2015, 2018-2020 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 #ifndef YCL_INC_Keys_h_
29 #define YCL_INC_Keys_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YCLib_YCommon
33 #include <bitset>
34
35 namespace platform
36 {
37
42 using KeyIndex = size_t;
43
50 #if YCL_DS
51 yconstexpr const KeyIndex KeyBitsetWidth(32);
52 #elif YCL_Win32 || YCL_Android || YCL_OS_X
53 yconstexpr const KeyIndex KeyBitsetWidth(256);
54 #elif YCL_Linux
55 yconstexpr const KeyIndex KeyBitsetWidth(0x200);
56 #else
57 # error "Unsupported platform found."
58 #endif
59
60
67 using KeyInput = std::bitset<KeyBitsetWidth>;
68
69
76 YF_API YB_PURE KeyIndex
77 FindFirstKey(const KeyInput&) ynothrow;
78
85 YF_API YB_PURE KeyIndex
86 FindNextKey(const KeyInput&, KeyIndex) ynothrow;
87
88
94 namespace KeyCategory
95 {
96
98 enum Category : std::uint_least32_t
99 {
101 None = 0,
103 Alphabetic = 1 << 1,
105 Numeric = 1 << 2,
107 Alphanumeric = Alphabetic | Numeric,
109 Punctuation = 1 << 3,
111 Character = Alphanumeric | Punctuation,
113 Dead = 1 << 4,
115 Lock = 2 << 4,
117 Modifier = 1 << 6,
119 Function = 1 << 7,
121 Navigation = 1 << 8,
123 Editing = 1 << 9,
125 System = 1 << 10,
127 IME = 1 << 11,
129 OEM = 1 << 12,
131 Menu = 1 << 13,
133 Keypad = 1 << 14,
135 NonKeyboard = 2 << 14,
137 Composed = 1 << 16,
139 Virtual = 2 << 16
140 };
141
143 DefBitmaskEnum(Category)
144
145
146
148
152 YF_API YB_STATELESS Category
153 ClassifyKey(KeyIndex) ynothrow;
154
159 YF_API YB_PURE KeyIndex
160 FindFirstKeyInCategroy(const KeyInput&, KeyIndex) ynothrow;
161
163 #if YCL_Win32
164 YB_PURE inline PDefH(bool, IsComposedKey, KeyIndex code) ynothrow
165 ImplRet(ClassifyKey(code))
166 #else
167 yconstfn PDefH(bool, IsComposedKey, KeyIndex) ynothrow
168 ImplRet({})
169 #endif
171 } // namespace KeyCategory;
173
174
183 #if YCL_Win32
184 YF_API char
185 MapKeyChar(KeyIndex) ynothrow;
186 YF_API char
187 MapKeyChar(const KeyInput&, KeyIndex) ynothrow;
188 #else
189 yconstfn PDefH(char, MapKeyChar, KeyIndex) ynothrow
190 ImplRet({})
192 yconstfn PDefH(char, MapKeyChar, const KeyInput&, KeyIndex) ynothrow
193 ImplRet({})
194 #endif
196
197
203 namespace KeyCodes
204 {
205
207
208 namespace DS
209 {
210
212 enum NativeSet
213 {
215
216 A = 0,
217 B = 1,
218 Select = 2,
219 Start = 3,
221 Right = 4,
222 Left = 5,
223 Up = 6,
224 Down = 7,
226
227 R = 8,
228 L = 9,
229 X = 10,
230 Y = 11,
231 Touch = 12,
232 Lid = 13
234 };
235
237
238 static yconstexpr const NativeSet Enter = A, Esc = B, PgUp = L, PgDn = R;
240 static yconstexpr const NativeSet Home = X, End = Y;
242 static yconstexpr const NativeSet Primary = Touch;
244
250 enum ExtendedSet
251 {
252 Backspace = 14,
253 Tab,
254 Shift,
255 Ctrl,
256 Alt,
257 Pause,
258 CapsLock,
260 Space,
261 Insert,
262 Delete,
264 Secondary,
266 Tertiary
267 };
268
269 } // namespace DS;
270
271
272 namespace Win32
273 {
274
280 enum NativeSet
281 {
282 Empty = 0,
284
285 Primary = 0x01,
288 Secondary = 0x02,
290 Tertiary = 0x04,
292
294 Backspace = 0x08,
297 Tab = 0x09,
299 Enter = 0x0D,
302
303 Shift = 0x10,
306 Ctrl = 0x11,
308 Alt = 0x12,
310 Pause = 0x13,
312 CapsLock = 0x14,
314 Esc = 0x1B,
320 Space = 0x20,
322 PgUp = 0x21,
324 PgDn = 0x22,
326
327 End = 0x23,
330 Home = 0x24,
332 Left = 0x25,
335 Up = 0x26,
337 Right = 0x27,
339 Down = 0x28,
341
342 Insert = 0x2D,
345 Delete = 0x2E
347 };
348
349 } // namespace Win32;
350
351
352 namespace Android
353 {
354
360 enum NativeSet
361 {
363 Empty = 0,
365 Up = 0x13,
367 Down = 0x14,
369 Left = 0x15,
371 Right = 0x16,
373 Alt = 0x39,
375 Shift = 0x3B,
377 Tab = 0x3D,
379 Space = 0x3E,
381 Enter = 0x42,
383 Backspace = 0x43,
385 PgUp = 0x5C,
387 PgDn = 0x5D,
389 Esc = 0x6F,
391 Delete = 0x70,
393 Ctrl = 0x71,
395 CapsLock = 0x73,
397 Pause = 0x79,
399 Home = 0x7A,
401 End = 0x7B,
403 Insert = 0x7C
404 };
405
407 enum ExtendedSet
408 {
409 Primary = 0xE0,
410 Secondary = 0xE1,
411 Tertiary = 0xE2
412 };
413
414 } // namespace Android;
415
416
417 namespace Linux
418 {
419
425 enum NativeSet
426 {
428 Empty = 0,
430 Esc = 1,
432 Backspace = 14,
434 Tab = 15,
436 Enter = 28,
438 Ctrl = 29,
440 Shift = 42,
442 Alt = 56,
444 Space = 57,
446 CapsLock = 58,
448 Home = 102,
450 Up = 103,
452 PgUp = 104,
454 Left = 105,
456 Right = 106,
458 End = 107,
460 Down = 108,
462 PgDn = 109,
464 Insert = 110,
466 Delete = 111,
468 Pause = 119,
470 Primary = 0x110,
472 Secondary = 0x111,
474 Tertiary = 0x112
475 };
476
477 } // namespace Linux;
479
480 #if YCL_DS
481 using namespace DS;
483 #elif YCL_Win32
484 using namespace Win32;
486 #elif YCL_Android
487 using namespace Android;
489 #elif YCL_Linux
490 using namespace Linux;
492 #endif
493
494
501 YF_API bool
502 FetchLockState(KeyIndex) ynothrow;
503
510 YF_API void
511 ToggleLockState(KeyIndex) ynothrow;
512
513 } // namespace KeyCodes;
514
515 } // namespace platform;
516
517 #endif
518
platform::KeyCodes::Linux::Primary
@ Primary
Definition: Keys.h:470
platform::KeyCodes::Linux::Space
@ Space
Definition: Keys.h:444
platform::KeyCodes::ToggleLockState
YF_API void ToggleLockState(KeyIndex) ynothrow
切换锁定键状态。
platform::KeyCodes::DS::Down
@ Down
Definition: Keys.h:224
platform::KeyCategory::Keypad
@ Keypad
表示小键盘键。
Definition: Keys.h:133
platform::KeyCodes::Linux::Backspace
@ Backspace
Definition: Keys.h:432
platform::KeyCategory::PDefH
yconstfn PDefH(bool, IsComposedKey, KeyIndex) ynothrow ImplRet(
判断指定按键编码是否通过多个物理按键组合构成。
Definition: Keys.h:167
platform::KeyCategory::Modifier
@ Modifier
表示修饰键。
Definition: Keys.h:117
platform::KeyCodes::FetchLockState
YF_API bool FetchLockState(KeyIndex) ynothrow
取锁定键状态。
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
platform::KeyCodes::Linux::Insert
@ Insert
Definition: Keys.h:464
platform::KeyCategory::Punctuation
@ Punctuation
表示产生标点字符的键。
Definition: Keys.h:109
platform::KeyCategory
按键类别。
Definition: Keys.h:95
platform::KeyCodes::Android::NativeSet
NativeSet
基本公用按键集合。
Definition: Keys.h:361
platform::KeyCategory::Navigation
@ Navigation
表示导航键（如方向键和 PgUp ）、菜单键和 Esc 。
Definition: Keys.h:121
platform::KeyCategory::Category
Category
按键类别。
Definition: Keys.h:99
platform::KeyCodes::Win32::NativeSet
NativeSet
基本公用按键集合。
Definition: Keys.h:281
platform::size_t
YB_ATTR_nodiscard YF_API size_t
Definition: FileIO.h:1345
platform::KeyCodes::Linux::Home
@ Home
Definition: Keys.h:448
YF_API
#define YF_API
Definition: Platform.h:56
platform::KeyCodes::Linux::Tab
@ Tab
Definition: Keys.h:434
platform::KeyCodes::DS::B
@ B
Definition: Keys.h:217
platform::FindNextKey
YF_API YB_PURE KeyIndex FindNextKey(const KeyInput &, KeyIndex) ynothrow
找到输入缓冲区记录中大于指定编码的最小的按键编码。
Definition: Keys.cpp:71
platform::KeyCodes::DS::Delete
@ Delete
Definition: Keys.h:262
platform::KeyCodes::Linux::CapsLock
@ CapsLock
Definition: Keys.h:446
platform::KeyCodes::DS::Select
@ Select
Definition: Keys.h:218
platform::KeyCategory::Menu
@ Menu
表示菜单键（如 Menu 和 Win ）。
Definition: Keys.h:131
platform::KeyCategory::Alphanumeric
@ Alphanumeric
表示产生字母或数字字符的键。
Definition: Keys.h:107
platform::KeyCategory::Lock
@ Lock
表示锁定键。
Definition: Keys.h:115
platform::KeyCodes::DS::Touch
@ Touch
Definition: Keys.h:231
platform::KeyCategory::Numeric
@ Numeric
表示产生数字字符的键。
Definition: Keys.h:105
platform::KeyCodes::DS::A
@ A
Definition: Keys.h:216
platform::FindFirstKey
YF_API YB_PURE KeyIndex FindFirstKey(const KeyInput &) ynothrow
找到输入缓冲区记录中最小的按键编码。
Definition: Keys.cpp:60
platform::KeyCodes::Linux::Secondary
@ Secondary
Definition: Keys.h:472
platform::ImplRet
YB_ATTR_nodiscard const char *s ImplRet(Nonnull(s)) YB_ATTR_nodiscard inline PDefH(const string &
platform::ynothrow
const _tString &path ynothrow
Definition: YCLib/FileSystem.h:453
platform::KeyCodes::Linux::Esc
@ Esc
Definition: Keys.h:430
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
platform::KeyCategory::Function
@ Function
表示功能键。
Definition: Keys.h:119
platform::KeyCodes::Linux::Enter
@ Enter
Definition: Keys.h:436
platform::KeyCodes::Linux::Alt
@ Alt
Definition: Keys.h:442
platform::KeyCategory::Dead
@ Dead
表示按键顺序相关的组合键。
Definition: Keys.h:113
platform::KeyCodes::DS::X
@ X
Definition: Keys.h:229
platform::KeyCodes
本机按键编码。
Definition: Keys.h:204
platform::KeyCategory::Editing
@ Editing
表示编辑键（如回车、空格、退格、插入、删除和制表符）
Definition: Keys.h:123
platform::KeyCategory::None
@ None
表示未分配或保留的键。
Definition: Keys.h:101
platform::KeyCodes::Linux::Tertiary
@ Tertiary
Definition: Keys.h:474
platform::KeyCodes::DS::L
@ L
Definition: Keys.h:228
platform::KeyCodes::DS::Up
@ Up
Definition: Keys.h:223
platform::KeyCodes::DS::Y
@ Y
Definition: Keys.h:230
platform::KeyCategory::Alphabetic
@ Alphabetic
表示产生字母字符的键。
Definition: Keys.h:103
platform
默认平台命名空间。
Definition: Container.h:56
platform::KeyInput
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。
Definition: Keys.h:67
platform::KeyCodes::Linux::Shift
@ Shift
Definition: Keys.h:440
platform::KeyCodes::Linux::Ctrl
@ Ctrl
Definition: Keys.h:438
YModules.h
YSLib 用户界面模块配置文件。
platform::KeyCategory::System
@ System
表示系统键（如 SysRq/PrintScr 、 Break/Pause 和电源管理）。
Definition: Keys.h:125
platform::KeyCodes::DS::Lid
@ Lid
Definition: Keys.h:232
platform::KeyCodes::DS::NativeSet
NativeSet
Definition: Keys.h:213
platform::KeyCategory::OEM
@ OEM
表示默认由设备制造商指定。
Definition: Keys.h:129
platform::KeyCodes::Linux::End
@ End
Definition: Keys.h:458
platform::KeyIndex
size_t KeyIndex
按键索引类型：标识特定的按键在按键集合中的位置。
Definition: Keys.h:42
platform::KeyCategory::ClassifyKey
Category ClassifyKey(KeyIndex code) ynothrow
Definition: Keys.cpp:1132
platform::KeyCategory::FindFirstKeyInCategroy
YF_API YB_PURE KeyIndex FindFirstKeyInCategroy(const KeyInput &, KeyIndex) ynothrow
找到第一个在指定类别的按键编码。
Definition: Keys.cpp:1139
platform::KeyCategory::IME
@ IME
表示输入法模式键（一般用于日文和韩文）。
Definition: Keys.h:127
platform::KeyCodes::DS::Start
@ Start
Definition: Keys.h:219
platform::KeyCodes::Win32::Empty
@ Empty
Definition: Keys.h:282
platform::KeyCodes::Linux::Pause
@ Pause
Definition: Keys.h:468
platform::KeyCodes::Linux::PgUp
@ PgUp
Definition: Keys.h:452
platform::PDefH
YB_ATTR_nodiscard PDefH(string, MakePathString, u16string_view sv) ImplRet(MakePathString(sv.data())) using FileNodeID
文件节点标识类型。
platform::KeyCodes::Linux::PgDn
@ PgDn
Definition: Keys.h:462
platform::KeyCategory::Character
@ Character
表示产生字符的键。
Definition: Keys.h:111
DefBitmaskEnum
#define DefBitmaskEnum(_tEnum)
Definition: YBaseMacro.h:505
platform::KeyCodes::DS::R
@ R
Definition: Keys.h:227
platform::KeyCodes::DS::ExtendedSet
ExtendedSet
扩展集：作为 DS 可直接被 KeyInput 表示的非物理键按键编码。
Definition: Keys.h:251
platform::KeyCodes::DS::Left
@ Left
Definition: Keys.h:222
platform::KeyCategory::NonKeyboard
@ NonKeyboard
表示非键盘键（如鼠标键）。
Definition: Keys.h:135
platform::KeyCodes::Android::ExtendedSet
ExtendedSet
Definition: Keys.h:408
platform::KeyCodes::DS::Right
@ Right
Definition: Keys.h:221
platform::KeyCategory::Virtual
@ Virtual
表示没有对应单一物理按键的虚拟键。
Definition: Keys.h:139
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
platform::KeyCodes::Linux::NativeSet
NativeSet
基本公用按键集合。
Definition: Keys.h:426
platform::KeyCategory::Composed
@ Composed
表示通过多个物理按键组合构成的键。
Definition: Keys.h:137