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
KeyCode combine(KeyCode key, KeyCode modifier)
Convenience method to create key combinations (hides ugly casts).
Definition: Keys.hh:231
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:25
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:589
KeyCode getCode(string_view name)
Definition: Keys.cc:341