openMSX
Keys.hh
Go to the documentation of this file.
1 #ifndef KEYS_HH
2 #define KEYS_HH
3 
4 #include "string_view.hh"
5 #include <SDL_stdinc.h>
6 #include <SDL_keycode.h>
7 #include <string>
8 
9 namespace openmsx {
10 namespace 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 
220 
221 KeyCode getCode(SDL_Keycode key, Uint16 mod = KMOD_NONE, SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN, bool release = false);
222 
227 std::string getName(KeyCode keyCode);
228 
232 inline KeyCode combine(KeyCode key, KeyCode modifier) {
233  return static_cast<KeyCode>(int(key) | int(modifier));
234 }
235 
236 } // namespace Keys
237 } // namespace openmsx
238 
239 #endif
KeyCode combine(KeyCode key, KeyCode modifier)
Convenience method to create key combinations (hides ugly casts).
Definition: Keys.hh:232
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:589
KeyCode getCode(string_view name)
Translate key name to key code.
Definition: Keys.cc:341