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