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
10namespace openmsx::Keys {
11
26enum KeyCode {
27 K_MASK = 0x1FFFF,
28
29 K_NONE = K_MASK, // make sure K_NONE has no modifiers set
32 K_TAB = 9,
33 K_CLEAR = 12,
35 K_PAUSE = 19,
37 K_SPACE = ' ',
38 K_EXCLAIM = '!',
40 K_HASH = '#',
41 K_DOLLAR = '$',
43 K_QUOTE = '\'',
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 = ':',
64 K_LESS = '<',
65 K_EQUALS = '=',
66 K_GREATER = '>',
68 K_AT = '@',
69
73 K_CARET = '^',
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,
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,
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
214
219[[nodiscard]] KeyCode getCode(std::string_view name);
220
222[[nodiscard]] std::pair<KeyCode, KeyCode> getCodes(
223 SDL_Keycode keyCode, Uint16 mod = KMOD_NONE, SDL_Scancode scanCode = SDL_SCANCODE_UNKNOWN, bool release = false);
224
229[[nodiscard]] std::string getName(KeyCode keyCode);
230
234[[nodiscard]] 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
KeyCode combine(KeyCode key, KeyCode modifier)
Convenience method to create key combinations (hides ugly casts).
Definition: Keys.hh:234
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
@ K_QUESTION
Definition: Keys.hh:67
@ K_UNDERSCORE
Definition: Keys.hh:74
@ K_HIRAGANA_KATAKANA
Definition: Keys.hh:201
@ K_BACKQUOTE
Definition: Keys.hh:75
@ K_MUHENKAN
Definition: Keys.hh:199
@ K_ESCAPE
Definition: Keys.hh:36
@ K_KP_EQUALS
Definition: Keys.hh:121
@ K_HENKAN_MODE
Definition: Keys.hh:200
@ K_EXCLAIM
Definition: Keys.hh:38
@ K_KP_MULTIPLY
Definition: Keys.hh:117
@ K_BACKSPACE
Definition: Keys.hh:31
@ K_RIGHTBRACKET
Definition: Keys.hh:72
@ K_EQUALS
Definition: Keys.hh:65
@ KD_RELEASE
Definition: Keys.hh:212
@ K_KP_ENTER
Definition: Keys.hh:120
@ K_KP_PERIOD
Definition: Keys.hh:115
@ K_UNKNOWN
Definition: Keys.hh:30
@ K_PERIOD
Definition: Keys.hh:50
@ K_SEMICOLON
Definition: Keys.hh:63
@ K_DOLLAR
Definition: Keys.hh:41
@ K_ZENKAKU_HENKAKU
Definition: Keys.hh:198
@ K_KP_DIVIDE
Definition: Keys.hh:116
@ K_CAPSLOCK
Definition: Keys.hh:162
@ K_GREATER
Definition: Keys.hh:66
@ K_QUOTEDBL
Definition: Keys.hh:39
@ K_RIGHTPAREN
Definition: Keys.hh:45
@ K_BACKSLASH
Definition: Keys.hh:71
@ K_SCROLLLOCK
Definition: Keys.hh:163
@ K_RETURN
Definition: Keys.hh:34
@ K_PAGEDOWN
Definition: Keys.hh:132
@ K_KP_MINUS
Definition: Keys.hh:118
@ K_LEFTPAREN
Definition: Keys.hh:44
@ K_AMPERSAND
Definition: Keys.hh:42
@ K_LEFTBRACKET
Definition: Keys.hh:70
@ K_ASTERISK
Definition: Keys.hh:46
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:357
KeyCode getCode(string_view name)
Translate key name to key code.
Definition: Keys.cc:330
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:730