openMSX
Keys.hh
Go to the documentation of this file.
1 #ifndef KEYS_HH
2 #define KEYS_HH
3 
4 #include <SDL_stdinc.h>
5 #include <SDL_keycode.h>
6 #include <string>
7 #include <string_view>
8 
9 namespace openmsx::Keys {
10 
25 enum KeyCode {
26  K_MASK = 0x1FFFF,
27 
28  K_NONE = K_MASK, // make sure K_NONE has no modifiers set
29  K_UNKNOWN = 0,
31  K_TAB = 9,
32  K_CLEAR = 12,
33  K_RETURN = 13,
34  K_PAUSE = 19,
35  K_ESCAPE = 27,
36  K_SPACE = ' ',
37  K_EXCLAIM = '!',
38  K_QUOTEDBL = '"',
39  K_HASH = '#',
40  K_DOLLAR = '$',
41  K_AMPERSAND = '&',
42  K_QUOTE = '\'',
43  K_LEFTPAREN = '(',
44  K_RIGHTPAREN = ')',
45  K_ASTERISK = '*',
46  K_PLUS = '+',
47  K_COMMA = ',',
48  K_MINUS = '-',
49  K_PERIOD = '.',
50  K_SLASH = '/',
51  K_0 = '0',
52  K_1 = '1',
53  K_2 = '2',
54  K_3 = '3',
55  K_4 = '4',
56  K_5 = '5',
57  K_6 = '6',
58  K_7 = '7',
59  K_8 = '8',
60  K_9 = '9',
61  K_COLON = ':',
62  K_SEMICOLON = ';',
63  K_LESS = '<',
64  K_EQUALS = '=',
65  K_GREATER = '>',
66  K_QUESTION = '?',
67  K_AT = '@',
68 
70  K_BACKSLASH = '\\',
72  K_CARET = '^',
73  K_UNDERSCORE = '_',
74  K_BACKQUOTE = '`',
75  K_A = 'a',
76  K_B = 'b',
77  K_C = 'c',
78  K_D = 'd',
79  K_E = 'e',
80  K_F = 'f',
81  K_G = 'g',
82  K_H = 'h',
83  K_I = 'i',
84  K_J = 'j',
85  K_K = 'k',
86  K_L = 'l',
87  K_M = 'm',
88  K_N = 'n',
89  K_O = 'o',
90  K_P = 'p',
91  K_Q = 'q',
92  K_R = 'r',
93  K_S = 's',
94  K_T = 't',
95  K_U = 'u',
96  K_V = 'v',
97  K_W = 'w',
98  K_X = 'x',
99  K_Y = 'y',
100  K_Z = 'z',
101  K_DELETE = 127,
102 
103  // Numeric keypad
104  K_KP0 = 0x100,
105  K_KP1 = 0x101,
106  K_KP2 = 0x102,
107  K_KP3 = 0x103,
108  K_KP4 = 0x104,
109  K_KP5 = 0x105,
110  K_KP6 = 0x106,
111  K_KP7 = 0x107,
112  K_KP8 = 0x108,
113  K_KP9 = 0x109,
114  K_KP_PERIOD = 0x10A,
115  K_KP_DIVIDE = 0x10B,
116  K_KP_MULTIPLY = 0x10C,
117  K_KP_MINUS = 0x10D,
118  K_KP_PLUS = 0x10E,
119  K_KP_ENTER = 0x10F,
120  K_KP_EQUALS = 0x110,
121 
122  // Arrows + Home/End pad
123  K_UP = 0x111,
124  K_DOWN = 0x112,
125  K_RIGHT = 0x113,
126  K_LEFT = 0x114,
127  K_INSERT = 0x115,
128  K_HOME = 0x116,
129  K_END = 0x117,
130  K_PAGEUP = 0x118,
131  K_PAGEDOWN = 0x119,
132 
133  // Function keys
134  K_F1 = 0x11A,
135  K_F2 = 0x11B,
136  K_F3 = 0x11C,
137  K_F4 = 0x11D,
138  K_F5 = 0x11E,
139  K_F6 = 0x11F,
140  K_F7 = 0x120,
141  K_F8 = 0x121,
142  K_F9 = 0x122,
143  K_F10 = 0x123,
144  K_F11 = 0x124,
145  K_F12 = 0x125,
146  K_F13 = 0x126,
147  K_F14 = 0x127,
148  K_F15 = 0x128,
149  K_F16 = 0x129,
150  K_F17 = 0x12A,
151  K_F18 = 0x12B,
152  K_F19 = 0x144, // NOTE: continuing at 0x144
153  K_F20 = 0x145,
154  K_F21 = 0x146,
155  K_F22 = 0x147,
156  K_F23 = 0x148,
157  K_F24 = 0x149,
158 
159  // Key state modifier keys
160  K_NUMLOCK = 0x12C, // NOTE: here we continue at 0x12C
161  K_CAPSLOCK = 0x12D,
162  K_SCROLLLOCK = 0x12E,
163  K_RSHIFT = 0x12F,
164  K_LSHIFT = 0x130,
165  K_RCTRL = 0x131,
166  K_LCTRL = 0x132,
167  K_RALT = 0x133,
168  K_LALT = 0x134,
169 // K_RMETA = 0x135,
170 // K_LMETA = 0x136,
171  K_LSUPER = 0x137, // Left "Windows" key
172  K_RSUPER = 0x138, // Right "Windows" key
173  K_MODE = 0x139, // "Alt Gr" key
174 // K_COMPOSE = 0x13A, // Multi-key compose key
175 
176  // Miscellaneous function keys
177  K_HELP = 0x13B,
178  K_PRINT = 0x13C,
179  K_SYSREQ = 0x13D,
180 // K_BREAK = 0x13E,
181  K_MENU = 0x13F,
182  K_POWER = 0x140, // Power Macintosh power key
183 // K_EURO = 0x141, // Some european keyboards
184  K_UNDO = 0x142,
185 
186  // Application Control keys
187  K_BACK = 0x143,
188 
189  // Some japanese keyboard keys are unknown to SDL.
190  // That is; they are all mapped to SDL_Keycode=0
191  // However, they can be recognized on their scancode
192  // These keys are useful for Japanese users who want to map
193  // their host keyboard to the Japanese MSX keyboard
194  // (e.g. the MSX turbo R keyboard)
195  // Define some codes above suspected SDL_Keycode value range, to
196  // avoid clash with SDL_Keycode values
197  K_ZENKAKU_HENKAKU = 0x10000, // Enables EMI mode (MSX does this with CTRL+SPACE)
198  K_MUHENKAN = 0x10001, // ???
199  K_HENKAN_MODE = 0x10002, // Similar to kanalock on MSX
200  K_HIRAGANA_KATAKANA = 0x10003, // MSX switches between the two sets based on capslock state
201 
202  // Modifiers
203  KM_SHIFT = 0x020000,
204  KM_CTRL = 0x040000,
205  KM_ALT = 0x080000,
206  KM_META = 0x100000,
207  KM_MODE = 0x200000,
208 
209  // Direction modifiers
210  KD_PRESS = 0, // key press
211  KD_RELEASE = 0x400000 // key release
212 };
213 
218 KeyCode getCode(std::string_view name);
219 
220 KeyCode getCode(SDL_Keycode key, Uint16 mod = KMOD_NONE, SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN, bool release = false);
221 
226 std::string getName(KeyCode keyCode);
227 
231 inline KeyCode combine(KeyCode key, KeyCode modifier) {
232  return static_cast<KeyCode>(int(key) | int(modifier));
233 }
234 
235 } // namespace openmsx::Keys
236 
237 #endif
openmsx::Keys::K_PAUSE
Definition: Keys.hh:34
openmsx::Keys::K_COLON
Definition: Keys.hh:61
openmsx::Keys::K_CLEAR
Definition: Keys.hh:32
openmsx::Keys::K_RSHIFT
Definition: Keys.hh:163
openmsx::Keys::K_F5
Definition: Keys.hh:138
openmsx::Keys::K_QUESTION
Definition: Keys.hh:66
openmsx::Keys::K_N
Definition: Keys.hh:88
openmsx::Keys::K_INSERT
Definition: Keys.hh:127
openmsx::Keys::K_ESCAPE
Definition: Keys.hh:35
openmsx::Keys::KM_META
Definition: Keys.hh:206
openmsx::Keys::K_F9
Definition: Keys.hh:142
openmsx::Keys::K_R
Definition: Keys.hh:92
openmsx::Keys::K_O
Definition: Keys.hh:89
openmsx::Keys::K_SCROLLLOCK
Definition: Keys.hh:162
openmsx::Keys::K_SYSREQ
Definition: Keys.hh:179
openmsx::Keys::K_EXCLAIM
Definition: Keys.hh:37
openmsx::Keys::K_F22
Definition: Keys.hh:155
openmsx::Keys::K_F6
Definition: Keys.hh:139
openmsx::Keys::K_A
Definition: Keys.hh:75
openmsx::Keys::K_KP_MINUS
Definition: Keys.hh:117
openmsx::Keys::K_W
Definition: Keys.hh:97
openmsx::Keys::K_KP1
Definition: Keys.hh:105
openmsx::Keys::K_Y
Definition: Keys.hh:99
openmsx::Keys::K_HIRAGANA_KATAKANA
Definition: Keys.hh:200
openmsx::Keys::K_Q
Definition: Keys.hh:91
openmsx::Keys::K_LSHIFT
Definition: Keys.hh:164
openmsx::Keys::K_NUMLOCK
Definition: Keys.hh:160
openmsx::Keys::K_RIGHTPAREN
Definition: Keys.hh:44
openmsx::Keys::K_Z
Definition: Keys.hh:100
openmsx::Keys::K_6
Definition: Keys.hh:57
openmsx::Keys::K_G
Definition: Keys.hh:81
openmsx::Keys::K_C
Definition: Keys.hh:77
openmsx::Keys::K_KP_PERIOD
Definition: Keys.hh:114
openmsx::Keys::K_KP0
Definition: Keys.hh:104
openmsx::Keys::K_RIGHT
Definition: Keys.hh:125
openmsx::Keys::K_5
Definition: Keys.hh:56
openmsx::Keys::K_UNDO
Definition: Keys.hh:184
openmsx::Keys::K_CARET
Definition: Keys.hh:72
openmsx::Keys::K_COMMA
Definition: Keys.hh:47
openmsx::Keys::K_2
Definition: Keys.hh:53
openmsx::Keys::K_F2
Definition: Keys.hh:135
openmsx::Keys::K_9
Definition: Keys.hh:60
openmsx::Keys::K_EQUALS
Definition: Keys.hh:64
openmsx::Keys::K_F3
Definition: Keys.hh:136
openmsx::Keys::K_F23
Definition: Keys.hh:156
openmsx::Keys::combine
KeyCode combine(KeyCode key, KeyCode modifier)
Convenience method to create key combinations (hides ugly casts).
Definition: Keys.hh:231
openmsx::Keys::K_SPACE
Definition: Keys.hh:36
openmsx::Keys::K_DOLLAR
Definition: Keys.hh:40
openmsx::Keys::K_F15
Definition: Keys.hh:148
openmsx::Keys::K_F19
Definition: Keys.hh:152
openmsx::Keys::K_J
Definition: Keys.hh:84
openmsx::Keys::K_RALT
Definition: Keys.hh:167
openmsx::Keys::K_RCTRL
Definition: Keys.hh:165
openmsx::Keys::K_F11
Definition: Keys.hh:144
openmsx::Keys::K_F1
Definition: Keys.hh:134
openmsx::Keys::K_KP_MULTIPLY
Definition: Keys.hh:116
openmsx::Keys::K_P
Definition: Keys.hh:90
openmsx::Keys
Definition: Keys.cc:10
openmsx::Keys::K_F12
Definition: Keys.hh:145
openmsx::Keys::K_NONE
Definition: Keys.hh:28
openmsx::Keys::K_SEMICOLON
Definition: Keys.hh:62
openmsx::Keys::K_KP6
Definition: Keys.hh:110
openmsx::Keys::K_H
Definition: Keys.hh:82
openmsx::Keys::K_DOWN
Definition: Keys.hh:124
openmsx::Keys::K_BACKQUOTE
Definition: Keys.hh:74
openmsx::Keys::K_KP3
Definition: Keys.hh:107
openmsx::Keys::K_F20
Definition: Keys.hh:153
openmsx::Keys::K_8
Definition: Keys.hh:59
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:589
openmsx::Keys::K_F17
Definition: Keys.hh:150
openmsx::Keys::K_RIGHTBRACKET
Definition: Keys.hh:71
openmsx::Keys::KM_ALT
Definition: Keys.hh:205
openmsx::Keys::getCode
KeyCode getCode(string_view name)
Definition: Keys.cc:341
openmsx::Keys::K_3
Definition: Keys.hh:54
openmsx::Keys::K_4
Definition: Keys.hh:55
openmsx::Keys::K_PRINT
Definition: Keys.hh:178
openmsx::Keys::K_BACK
Definition: Keys.hh:187
openmsx::Keys::K_D
Definition: Keys.hh:78
openmsx::Keys::K_AMPERSAND
Definition: Keys.hh:41
openmsx::Keys::K_PERIOD
Definition: Keys.hh:49
openmsx::Keys::K_I
Definition: Keys.hh:83
openmsx::Keys::KM_CTRL
Definition: Keys.hh:204
openmsx::Keys::K_F10
Definition: Keys.hh:143
openmsx::Keys::K_X
Definition: Keys.hh:98
openmsx::Keys::KD_PRESS
Definition: Keys.hh:210
openmsx::Keys::K_RSUPER
Definition: Keys.hh:172
openmsx::Keys::K_UNKNOWN
Definition: Keys.hh:29
openmsx::Keys::K_DELETE
Definition: Keys.hh:101
openmsx::Keys::K_KP2
Definition: Keys.hh:106
openmsx::Keys::K_7
Definition: Keys.hh:58
openmsx::Keys::K_AT
Definition: Keys.hh:67
openmsx::Keys::K_KP_EQUALS
Definition: Keys.hh:120
openmsx::Keys::K_BACKSPACE
Definition: Keys.hh:30
openmsx::Keys::K_U
Definition: Keys.hh:95
openmsx::Keys::K_CAPSLOCK
Definition: Keys.hh:161
openmsx::Keys::K_F8
Definition: Keys.hh:141
openmsx::Keys::K_ASTERISK
Definition: Keys.hh:45
openmsx::Keys::K_KP_ENTER
Definition: Keys.hh:119
openmsx::Keys::K_K
Definition: Keys.hh:85
openmsx::Keys::KM_SHIFT
Definition: Keys.hh:203
openmsx::Keys::K_F24
Definition: Keys.hh:157
openmsx::Keys::K_HASH
Definition: Keys.hh:39
openmsx::Keys::K_0
Definition: Keys.hh:51
openmsx::Keys::K_M
Definition: Keys.hh:87
openmsx::Keys::K_V
Definition: Keys.hh:96
openmsx::Keys::K_UP
Definition: Keys.hh:123
openmsx::Keys::K_F13
Definition: Keys.hh:146
openmsx::Keys::K_L
Definition: Keys.hh:86
openmsx::Keys::K_B
Definition: Keys.hh:76
openmsx::Keys::K_LEFT
Definition: Keys.hh:126
openmsx::Keys::K_KP7
Definition: Keys.hh:111
openmsx::Keys::K_ZENKAKU_HENKAKU
Definition: Keys.hh:197
openmsx::Keys::K_HELP
Definition: Keys.hh:177
openmsx::Keys::K_QUOTE
Definition: Keys.hh:42
openmsx::Keys::K_F
Definition: Keys.hh:80
openmsx::Keys::K_RETURN
Definition: Keys.hh:33
openmsx::Keys::K_F16
Definition: Keys.hh:149
openmsx::Keys::K_KP5
Definition: Keys.hh:109
openmsx::Keys::K_GREATER
Definition: Keys.hh:65
openmsx::Keys::K_KP4
Definition: Keys.hh:108
openmsx::Keys::K_SLASH
Definition: Keys.hh:50
openmsx::Keys::K_F7
Definition: Keys.hh:140
openmsx::Keys::K_QUOTEDBL
Definition: Keys.hh:38
openmsx::Keys::K_F4
Definition: Keys.hh:137
openmsx::Keys::K_PLUS
Definition: Keys.hh:46
openmsx::Keys::K_POWER
Definition: Keys.hh:182
openmsx::Keys::K_KP_PLUS
Definition: Keys.hh:118
openmsx::Keys::K_HENKAN_MODE
Definition: Keys.hh:199
openmsx::Keys::K_F14
Definition: Keys.hh:147
openmsx::Keys::K_MINUS
Definition: Keys.hh:48
openmsx::Keys::KeyCode
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:25
openmsx::Keys::K_S
Definition: Keys.hh:93
openmsx::Keys::K_LCTRL
Definition: Keys.hh:166
openmsx::Keys::K_PAGEDOWN
Definition: Keys.hh:131
openmsx::Keys::KM_MODE
Definition: Keys.hh:207
openmsx::Keys::K_LSUPER
Definition: Keys.hh:171
openmsx::Keys::K_MUHENKAN
Definition: Keys.hh:198
openmsx::Keys::K_TAB
Definition: Keys.hh:31
openmsx::Keys::K_F18
Definition: Keys.hh:151
openmsx::Keys::K_T
Definition: Keys.hh:94
openmsx::Keys::K_KP8
Definition: Keys.hh:112
openmsx::Keys::K_LALT
Definition: Keys.hh:168
openmsx::Keys::K_MODE
Definition: Keys.hh:173
openmsx::Keys::KD_RELEASE
Definition: Keys.hh:211
openmsx::Keys::K_MASK
Definition: Keys.hh:26
openmsx::Keys::K_PAGEUP
Definition: Keys.hh:130
openmsx::Keys::K_KP_DIVIDE
Definition: Keys.hh:115
openmsx::Keys::K_1
Definition: Keys.hh:52
openmsx::Keys::K_HOME
Definition: Keys.hh:128
openmsx::Keys::K_F21
Definition: Keys.hh:154
openmsx::Keys::K_LESS
Definition: Keys.hh:63
openmsx::Keys::K_MENU
Definition: Keys.hh:181
openmsx::Keys::K_KP9
Definition: Keys.hh:113
openmsx::Keys::K_END
Definition: Keys.hh:129
openmsx::Keys::K_LEFTBRACKET
Definition: Keys.hh:69
openmsx::Keys::K_LEFTPAREN
Definition: Keys.hh:43
openmsx::Keys::K_BACKSLASH
Definition: Keys.hh:70
openmsx::Keys::K_UNDERSCORE
Definition: Keys.hh:73
openmsx::Keys::K_E
Definition: Keys.hh:79