summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2024-03-04 07:05:28 +1100
committer Vas Crabb <vas@vastheman.com>2024-03-04 07:05:28 +1100
commit2931abbcf4ebb14c0c54765bd017424b256f2ea2 (patch)
tree19b299a8066ac18722114717b177c53ca6b4bdee /src
parent1dae50467e9b93512eb8e9115e5d61b69977805f (diff)
osd/modules/input: Various cleanup and minor enhancements.
input_common.h: Got rid of the DirectInput key code macros. DirectInput headers are always available on Windows - it's just an opportunity for bygs. input_common.cpp: Added default names for keys mapped to MAME's "other switch" type. input_rawinput.cpp: Simulate Pause key being held for 30ms, similarly to what's done for Caps Lock on macOS with SDL. Also added a gross hack to give "correct" names for Pause and Num Lock. input_sdl.cpp: Get default key names from SDL. Not really that useful as it isn't aware of the current keyboard layout. Key map files are still needed for anything other than a US ANSI layout. Also added some comments.
Diffstat (limited to 'src')
-rw-r--r--src/osd/modules/input/input_common.cpp291
-rw-r--r--src/osd/modules/input/input_common.h151
-rw-r--r--src/osd/modules/input/input_dinput.cpp2
-rw-r--r--src/osd/modules/input/input_rawinput.cpp73
-rw-r--r--src/osd/modules/input/input_sdl.cpp50
-rw-r--r--src/osd/modules/input/input_win32.cpp2
-rw-r--r--src/osd/windows/window.cpp6
7 files changed, 246 insertions, 329 deletions
diff --git a/src/osd/modules/input/input_common.cpp b/src/osd/modules/input/input_common.cpp
index ec9521ab4b8..f3de3ca186e 100644
--- a/src/osd/modules/input/input_common.cpp
+++ b/src/osd/modules/input/input_common.cpp
@@ -20,7 +20,9 @@
#if defined(OSD_WINDOWS) || defined(SDLMAME_WIN32)
#include <windows.h>
-#define KEY_TRANS_WIN32(disc, virtual) KEY_##disc, virtual,
+#include <dinput.h>
+#define DIK_UNKNOWN 0xffff // intentionally impossible
+#define KEY_TRANS_WIN32(disc, virtual) DIK_##disc, virtual,
#else
#define KEY_TRANS_WIN32(disc, virtual)
#endif
@@ -41,147 +43,147 @@
#endif
#if defined(OSD_WINDOWS) || defined(OSD_SDL)
+
key_trans_entry keyboard_trans_table::s_default_table[] =
{
- // MAME key sdl scancode di scancode virtual key ascii ui
- KEY_TRANS_ENTRY0(ESC, ESCAPE, ESCAPE, VK_ESCAPE, 27, "ESCAPE"),
- KEY_TRANS_ENTRY1(1, 1, 1, '1', '1'),
- KEY_TRANS_ENTRY1(2, 2, 2, '2', '2'),
- KEY_TRANS_ENTRY1(3, 3, 3, '3', '3'),
- KEY_TRANS_ENTRY1(4, 4, 4, '4', '4'),
- KEY_TRANS_ENTRY1(5, 5, 5, '5', '5'),
- KEY_TRANS_ENTRY1(6, 6, 6, '6', '6'),
- KEY_TRANS_ENTRY1(7, 7, 7, '7', '7'),
- KEY_TRANS_ENTRY1(8, 8, 8, '8', '8'),
- KEY_TRANS_ENTRY1(9, 9, 9, '9', '9'),
- KEY_TRANS_ENTRY1(0, 0, 0, '0', '0'),
- KEY_TRANS_ENTRY1(MINUS, MINUS, MINUS, VK_OEM_MINUS, '-'),
- KEY_TRANS_ENTRY1(EQUALS, EQUALS, EQUALS, VK_OEM_PLUS, '='),
- KEY_TRANS_ENTRY1(BACKSPACE, BACKSPACE, BACK, VK_BACK, 8),
- KEY_TRANS_ENTRY1(TAB, TAB, TAB, VK_TAB, 9),
- KEY_TRANS_ENTRY1(Q, Q, Q, 'Q', 'Q'),
- KEY_TRANS_ENTRY1(W, W, W, 'W', 'W'),
- KEY_TRANS_ENTRY1(E, E, E, 'E', 'E'),
- KEY_TRANS_ENTRY1(R, R, R, 'R', 'R'),
- KEY_TRANS_ENTRY1(T, T, T, 'T', 'T'),
- KEY_TRANS_ENTRY1(Y, Y, Y, 'Y', 'Y'),
- KEY_TRANS_ENTRY1(U, U, U, 'U', 'U'),
- KEY_TRANS_ENTRY1(I, I, I, 'I', 'I'),
- KEY_TRANS_ENTRY1(O, O, O, 'O', 'O'),
- KEY_TRANS_ENTRY1(P, P, P, 'P', 'P'),
- KEY_TRANS_ENTRY1(OPENBRACE, LEFTBRACKET, LBRACKET, VK_OEM_4, '['),
- KEY_TRANS_ENTRY1(CLOSEBRACE, RIGHTBRACKET, RBRACKET, VK_OEM_6, ']'),
- KEY_TRANS_ENTRY0(ENTER, RETURN, RETURN, VK_RETURN, 13, "RETURN"),
- KEY_TRANS_ENTRY1(LCONTROL, LCTRL, LCONTROL, VK_LCONTROL, 0),
- KEY_TRANS_ENTRY1(A, A, A, 'A', 'A'),
- KEY_TRANS_ENTRY1(S, S, S, 'S', 'S'),
- KEY_TRANS_ENTRY1(D, D, D, 'D', 'D'),
- KEY_TRANS_ENTRY1(F, F, F, 'F', 'F'),
- KEY_TRANS_ENTRY1(G, G, G, 'G', 'G'),
- KEY_TRANS_ENTRY1(H, H, H, 'H', 'H'),
- KEY_TRANS_ENTRY1(J, J, J, 'J', 'J'),
- KEY_TRANS_ENTRY1(K, K, K, 'K', 'K'),
- KEY_TRANS_ENTRY1(L, L, L, 'L', 'L'),
- KEY_TRANS_ENTRY1(COLON, SEMICOLON, SEMICOLON, VK_OEM_1, ';'),
- KEY_TRANS_ENTRY1(QUOTE, APOSTROPHE, APOSTROPHE, VK_OEM_7, '\''),
- KEY_TRANS_ENTRY1(TILDE, GRAVE, GRAVE, VK_OEM_3, '`'),
- KEY_TRANS_ENTRY1(LSHIFT, LSHIFT, LSHIFT, VK_LSHIFT, 0),
- KEY_TRANS_ENTRY1(BACKSLASH, BACKSLASH, BACKSLASH, VK_OEM_5, '\\'),
+ // MAME key SDL scancode DI scancode virtual key ASCII UI
+ KEY_TRANS_ENTRY0(ESC, ESCAPE, ESCAPE, VK_ESCAPE, 27, "ESCAPE"),
+ KEY_TRANS_ENTRY1(1, 1, 1, '1', '1'),
+ KEY_TRANS_ENTRY1(2, 2, 2, '2', '2'),
+ KEY_TRANS_ENTRY1(3, 3, 3, '3', '3'),
+ KEY_TRANS_ENTRY1(4, 4, 4, '4', '4'),
+ KEY_TRANS_ENTRY1(5, 5, 5, '5', '5'),
+ KEY_TRANS_ENTRY1(6, 6, 6, '6', '6'),
+ KEY_TRANS_ENTRY1(7, 7, 7, '7', '7'),
+ KEY_TRANS_ENTRY1(8, 8, 8, '8', '8'),
+ KEY_TRANS_ENTRY1(9, 9, 9, '9', '9'),
+ KEY_TRANS_ENTRY1(0, 0, 0, '0', '0'),
+ KEY_TRANS_ENTRY1(MINUS, MINUS, MINUS, VK_OEM_MINUS, '-'),
+ KEY_TRANS_ENTRY1(EQUALS, EQUALS, EQUALS, VK_OEM_PLUS, '='),
+ KEY_TRANS_ENTRY1(BACKSPACE, BACKSPACE, BACK, VK_BACK, 8),
+ KEY_TRANS_ENTRY1(TAB, TAB, TAB, VK_TAB, 9),
+ KEY_TRANS_ENTRY1(Q, Q, Q, 'Q', 'Q'),
+ KEY_TRANS_ENTRY1(W, W, W, 'W', 'W'),
+ KEY_TRANS_ENTRY1(E, E, E, 'E', 'E'),
+ KEY_TRANS_ENTRY1(R, R, R, 'R', 'R'),
+ KEY_TRANS_ENTRY1(T, T, T, 'T', 'T'),
+ KEY_TRANS_ENTRY1(Y, Y, Y, 'Y', 'Y'),
+ KEY_TRANS_ENTRY1(U, U, U, 'U', 'U'),
+ KEY_TRANS_ENTRY1(I, I, I, 'I', 'I'),
+ KEY_TRANS_ENTRY1(O, O, O, 'O', 'O'),
+ KEY_TRANS_ENTRY1(P, P, P, 'P', 'P'),
+ KEY_TRANS_ENTRY1(OPENBRACE, LEFTBRACKET, LBRACKET, VK_OEM_4, '['),
+ KEY_TRANS_ENTRY1(CLOSEBRACE, RIGHTBRACKET, RBRACKET, VK_OEM_6, ']'),
+ KEY_TRANS_ENTRY0(ENTER, RETURN, RETURN, VK_RETURN, 13, "RETURN"),
+ KEY_TRANS_ENTRY1(LCONTROL, LCTRL, LCONTROL, VK_LCONTROL, 0),
+ KEY_TRANS_ENTRY1(A, A, A, 'A', 'A'),
+ KEY_TRANS_ENTRY1(S, S, S, 'S', 'S'),
+ KEY_TRANS_ENTRY1(D, D, D, 'D', 'D'),
+ KEY_TRANS_ENTRY1(F, F, F, 'F', 'F'),
+ KEY_TRANS_ENTRY1(G, G, G, 'G', 'G'),
+ KEY_TRANS_ENTRY1(H, H, H, 'H', 'H'),
+ KEY_TRANS_ENTRY1(J, J, J, 'J', 'J'),
+ KEY_TRANS_ENTRY1(K, K, K, 'K', 'K'),
+ KEY_TRANS_ENTRY1(L, L, L, 'L', 'L'),
+ KEY_TRANS_ENTRY1(COLON, SEMICOLON, SEMICOLON, VK_OEM_1, ';'),
+ KEY_TRANS_ENTRY1(QUOTE, APOSTROPHE, APOSTROPHE, VK_OEM_7, '\''),
+ KEY_TRANS_ENTRY1(TILDE, GRAVE, GRAVE, VK_OEM_3, '`'),
+ KEY_TRANS_ENTRY1(LSHIFT, LSHIFT, LSHIFT, VK_LSHIFT, 0),
+ KEY_TRANS_ENTRY1(BACKSLASH, BACKSLASH, BACKSLASH, VK_OEM_5, '\\'),
// KEY_TRANS_ENTRY1(BACKSLASH2, NONUSHASH, UNKNOWN, OEM_102, VK_OEM_102, '<'),
// This is the additional key that ISO keyboards have over ANSI ones, located between left shift and Y.
- KEY_TRANS_ENTRY1(BACKSLASH2, NONUSBACKSLASH, OEM_102, VK_OEM_102, '<'),
- KEY_TRANS_ENTRY1(Z, Z, Z, 'Z', 'Z'),
- KEY_TRANS_ENTRY1(X, X, X, 'X', 'X'),
- KEY_TRANS_ENTRY1(C, C, C, 'C', 'C'),
- KEY_TRANS_ENTRY1(V, V, V, 'V', 'V'),
- KEY_TRANS_ENTRY1(B, B, B, 'B', 'B'),
- KEY_TRANS_ENTRY1(N, N, N, 'N', 'N'),
- KEY_TRANS_ENTRY1(M, M, M, 'M', 'M'),
- KEY_TRANS_ENTRY1(COMMA, COMMA, COMMA, VK_OEM_COMMA, ','),
- KEY_TRANS_ENTRY1(STOP, PERIOD, PERIOD, VK_OEM_PERIOD, '.'),
- KEY_TRANS_ENTRY1(SLASH, SLASH, SLASH, VK_OEM_2, '/'),
- KEY_TRANS_ENTRY1(RSHIFT, RSHIFT, RSHIFT, VK_RSHIFT, 0),
- KEY_TRANS_ENTRY1(ASTERISK, KP_MULTIPLY, MULTIPLY, VK_MULTIPLY, '*'),
- KEY_TRANS_ENTRY1(LALT, LALT, LMENU, VK_LMENU, 0),
- KEY_TRANS_ENTRY1(SPACE, SPACE, SPACE, VK_SPACE, ' '),
- KEY_TRANS_ENTRY1(CAPSLOCK, CAPSLOCK, CAPITAL, VK_CAPITAL, 0),
- KEY_TRANS_ENTRY1(F1, F1, F1, VK_F1, 0),
- KEY_TRANS_ENTRY1(F2, F2, F2, VK_F2, 0),
- KEY_TRANS_ENTRY1(F3, F3, F3, VK_F3, 0),
- KEY_TRANS_ENTRY1(F4, F4, F4, VK_F4, 0),
- KEY_TRANS_ENTRY1(F5, F5, F5, VK_F5, 0),
- KEY_TRANS_ENTRY1(F6, F6, F6, VK_F6, 0),
- KEY_TRANS_ENTRY1(F7, F7, F7, VK_F7, 0),
- KEY_TRANS_ENTRY1(F8, F8, F8, VK_F8, 0),
- KEY_TRANS_ENTRY1(F9, F9, F9, VK_F9, 0),
- KEY_TRANS_ENTRY1(F10, F10, F10, VK_F10, 0),
- KEY_TRANS_ENTRY1(NUMLOCK, NUMLOCKCLEAR, NUMLOCK, VK_NUMLOCK, 0),
- KEY_TRANS_ENTRY1(SCRLOCK, SCROLLLOCK, SCROLL, VK_SCROLL, 0),
- KEY_TRANS_ENTRY1(7_PAD, KP_7, NUMPAD7, VK_NUMPAD7, 0),
- KEY_TRANS_ENTRY1(8_PAD, KP_8, NUMPAD8, VK_NUMPAD8, 0),
- KEY_TRANS_ENTRY1(9_PAD, KP_9, NUMPAD9, VK_NUMPAD9, 0),
- KEY_TRANS_ENTRY1(MINUS_PAD, KP_MINUS, SUBTRACT, VK_SUBTRACT, 0),
- KEY_TRANS_ENTRY1(4_PAD, KP_4, NUMPAD4, VK_NUMPAD4, 0),
- KEY_TRANS_ENTRY1(5_PAD, KP_5, NUMPAD5, VK_NUMPAD5, 0),
- KEY_TRANS_ENTRY1(6_PAD, KP_6, NUMPAD6, VK_NUMPAD6, 0),
- KEY_TRANS_ENTRY1(PLUS_PAD, KP_PLUS, ADD, VK_ADD, 0),
- KEY_TRANS_ENTRY1(1_PAD, KP_1, NUMPAD1, VK_NUMPAD1, 0),
- KEY_TRANS_ENTRY1(2_PAD, KP_2, NUMPAD2, VK_NUMPAD2, 0),
- KEY_TRANS_ENTRY1(3_PAD, KP_3, NUMPAD3, VK_NUMPAD3, 0),
- KEY_TRANS_ENTRY1(0_PAD, KP_0, NUMPAD0, VK_NUMPAD0, 0),
- KEY_TRANS_ENTRY1(DEL_PAD, KP_PERIOD, DECIMAL, VK_DECIMAL, 0),
- KEY_TRANS_ENTRY1(F11, F11, F11, VK_F11, 0),
- KEY_TRANS_ENTRY1(F12, F12, F12, VK_F12, 0),
- KEY_TRANS_ENTRY1(F13, F13, F13, VK_F13, 0),
- KEY_TRANS_ENTRY1(F14, F14, F14, VK_F14, 0),
- KEY_TRANS_ENTRY1(F15, F15, F15, VK_F15, 0),
- KEY_TRANS_ENTRY1(ENTER_PAD, KP_ENTER, NUMPADENTER, VK_RETURN, 0),
- KEY_TRANS_ENTRY1(RCONTROL, RCTRL, RCONTROL, VK_RCONTROL, 0),
- KEY_TRANS_ENTRY1(SLASH_PAD, KP_DIVIDE, DIVIDE, VK_DIVIDE, 0),
- KEY_TRANS_ENTRY1(PRTSCR, PRINTSCREEN, SYSRQ, 0, 0),
- KEY_TRANS_ENTRY1(RALT, RALT, RMENU, VK_RMENU, 0),
- KEY_TRANS_ENTRY1(HOME, HOME, HOME, VK_HOME, 0),
- KEY_TRANS_ENTRY1(UP, UP, UP, VK_UP, 0),
- KEY_TRANS_ENTRY1(PGUP, PAGEUP, PRIOR, VK_PRIOR, 0),
- KEY_TRANS_ENTRY1(LEFT, LEFT, LEFT, VK_LEFT, 0),
- KEY_TRANS_ENTRY1(RIGHT, RIGHT, RIGHT, VK_RIGHT, 0),
- KEY_TRANS_ENTRY1(END, END, END, VK_END, 0),
- KEY_TRANS_ENTRY1(DOWN, DOWN, DOWN, VK_DOWN, 0),
- KEY_TRANS_ENTRY1(PGDN, PAGEDOWN, NEXT, VK_NEXT, 0),
- KEY_TRANS_ENTRY1(INSERT, INSERT, INSERT, VK_INSERT, 0),
- KEY_TRANS_ENTRY0(DEL, DELETE, DELETE, VK_DELETE, 0, "DELETE"),
- KEY_TRANS_ENTRY1(LWIN, LGUI, LWIN, VK_LWIN, 0),
- KEY_TRANS_ENTRY1(RWIN, RGUI, RWIN, VK_RWIN, 0),
- KEY_TRANS_ENTRY1(MENU, MENU, APPS, VK_APPS, 0),
- KEY_TRANS_ENTRY1(PAUSE, PAUSE, PAUSE, VK_PAUSE, 0),
- KEY_TRANS_ENTRY0(CANCEL, CANCEL, UNKNOWN, 0, 0, "CANCEL"),
- KEY_TRANS_ENTRY1(BS_PAD, KP_BACKSPACE, UNKNOWN, 0, 0),
- KEY_TRANS_ENTRY1(TAB_PAD, KP_TAB, UNKNOWN, 0, 0),
- KEY_TRANS_ENTRY1(00_PAD, KP_00, UNKNOWN, 0, 0),
- KEY_TRANS_ENTRY1(000_PAD, KP_000, UNKNOWN, 0, 0),
- KEY_TRANS_ENTRY1(COMMA_PAD, KP_COMMA, NUMPADCOMMA, 0, 0),
- KEY_TRANS_ENTRY1(EQUALS_PAD, KP_EQUALS, NUMPADEQUALS, 0, 0),
-
- // New keys introduced in Windows 2000. These have no MAME codes to
- // preserve compatibility with old config files that may refer to them
- // as e.g. FORWARD instead of e.g. KEYCODE_WEBFORWARD. They need table
- // entries anyway because otherwise they aren't recognized when
- // GetAsyncKeyState polling is used (as happens currently when MAME is
- // paused). Some codes are missing because the mapping to vkey codes
- // isn't clear, and MapVirtualKey is no help.
- KEY_TRANS_ENTRY1(OTHER_SWITCH, MUTE, MUTE, VK_VOLUME_MUTE, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, VOLUMEDOWN, VOLUMEDOWN, VK_VOLUME_DOWN, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, VOLUMEUP, VOLUMEUP, VK_VOLUME_UP, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, AC_HOME, WEBHOME, VK_BROWSER_HOME, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, AC_SEARCH, WEBSEARCH, VK_BROWSER_SEARCH, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, AC_BOOKMARKS, WEBFAVORITES, VK_BROWSER_FAVORITES, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, AC_REFRESH, WEBREFRESH, VK_BROWSER_REFRESH, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, AC_STOP, WEBSTOP, VK_BROWSER_STOP, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, AC_FORWARD, WEBFORWARD, VK_BROWSER_FORWARD, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, AC_BACK, WEBBACK, VK_BROWSER_BACK, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, MAIL, MAIL, VK_LAUNCH_MAIL, 0),
- KEY_TRANS_ENTRY1(OTHER_SWITCH, MEDIASELECT, MEDIASELECT, VK_LAUNCH_MEDIA_SELECT, 0),
- KEY_TRANS_ENTRY0(INVALID, UNKNOWN, ESCAPE, 0, 0, "INVALID")
+ KEY_TRANS_ENTRY1(BACKSLASH2, NONUSBACKSLASH, OEM_102, VK_OEM_102, '<'),
+ KEY_TRANS_ENTRY1(Z, Z, Z, 'Z', 'Z'),
+ KEY_TRANS_ENTRY1(X, X, X, 'X', 'X'),
+ KEY_TRANS_ENTRY1(C, C, C, 'C', 'C'),
+ KEY_TRANS_ENTRY1(V, V, V, 'V', 'V'),
+ KEY_TRANS_ENTRY1(B, B, B, 'B', 'B'),
+ KEY_TRANS_ENTRY1(N, N, N, 'N', 'N'),
+ KEY_TRANS_ENTRY1(M, M, M, 'M', 'M'),
+ KEY_TRANS_ENTRY1(COMMA, COMMA, COMMA, VK_OEM_COMMA, ','),
+ KEY_TRANS_ENTRY1(STOP, PERIOD, PERIOD, VK_OEM_PERIOD, '.'),
+ KEY_TRANS_ENTRY1(SLASH, SLASH, SLASH, VK_OEM_2, '/'),
+ KEY_TRANS_ENTRY1(RSHIFT, RSHIFT, RSHIFT, VK_RSHIFT, 0),
+ KEY_TRANS_ENTRY1(ASTERISK, KP_MULTIPLY, MULTIPLY, VK_MULTIPLY, '*'),
+ KEY_TRANS_ENTRY1(LALT, LALT, LMENU, VK_LMENU, 0),
+ KEY_TRANS_ENTRY1(SPACE, SPACE, SPACE, VK_SPACE, ' '),
+ KEY_TRANS_ENTRY1(CAPSLOCK, CAPSLOCK, CAPITAL, VK_CAPITAL, 0),
+ KEY_TRANS_ENTRY1(F1, F1, F1, VK_F1, 0),
+ KEY_TRANS_ENTRY1(F2, F2, F2, VK_F2, 0),
+ KEY_TRANS_ENTRY1(F3, F3, F3, VK_F3, 0),
+ KEY_TRANS_ENTRY1(F4, F4, F4, VK_F4, 0),
+ KEY_TRANS_ENTRY1(F5, F5, F5, VK_F5, 0),
+ KEY_TRANS_ENTRY1(F6, F6, F6, VK_F6, 0),
+ KEY_TRANS_ENTRY1(F7, F7, F7, VK_F7, 0),
+ KEY_TRANS_ENTRY1(F8, F8, F8, VK_F8, 0),
+ KEY_TRANS_ENTRY1(F9, F9, F9, VK_F9, 0),
+ KEY_TRANS_ENTRY1(F10, F10, F10, VK_F10, 0),
+ KEY_TRANS_ENTRY1(NUMLOCK, NUMLOCKCLEAR, NUMLOCK, VK_NUMLOCK, 0),
+ KEY_TRANS_ENTRY1(SCRLOCK, SCROLLLOCK, SCROLL, VK_SCROLL, 0),
+ KEY_TRANS_ENTRY1(7_PAD, KP_7, NUMPAD7, VK_NUMPAD7, 0),
+ KEY_TRANS_ENTRY1(8_PAD, KP_8, NUMPAD8, VK_NUMPAD8, 0),
+ KEY_TRANS_ENTRY1(9_PAD, KP_9, NUMPAD9, VK_NUMPAD9, 0),
+ KEY_TRANS_ENTRY1(MINUS_PAD, KP_MINUS, SUBTRACT, VK_SUBTRACT, 0),
+ KEY_TRANS_ENTRY1(4_PAD, KP_4, NUMPAD4, VK_NUMPAD4, 0),
+ KEY_TRANS_ENTRY1(5_PAD, KP_5, NUMPAD5, VK_NUMPAD5, 0),
+ KEY_TRANS_ENTRY1(6_PAD, KP_6, NUMPAD6, VK_NUMPAD6, 0),
+ KEY_TRANS_ENTRY1(PLUS_PAD, KP_PLUS, ADD, VK_ADD, 0),
+ KEY_TRANS_ENTRY1(1_PAD, KP_1, NUMPAD1, VK_NUMPAD1, 0),
+ KEY_TRANS_ENTRY1(2_PAD, KP_2, NUMPAD2, VK_NUMPAD2, 0),
+ KEY_TRANS_ENTRY1(3_PAD, KP_3, NUMPAD3, VK_NUMPAD3, 0),
+ KEY_TRANS_ENTRY1(0_PAD, KP_0, NUMPAD0, VK_NUMPAD0, 0),
+ KEY_TRANS_ENTRY1(DEL_PAD, KP_PERIOD, DECIMAL, VK_DECIMAL, 0),
+ KEY_TRANS_ENTRY1(F11, F11, F11, VK_F11, 0),
+ KEY_TRANS_ENTRY1(F12, F12, F12, VK_F12, 0),
+ KEY_TRANS_ENTRY1(F13, F13, F13, VK_F13, 0),
+ KEY_TRANS_ENTRY1(F14, F14, F14, VK_F14, 0),
+ KEY_TRANS_ENTRY1(F15, F15, F15, VK_F15, 0),
+ KEY_TRANS_ENTRY1(ENTER_PAD, KP_ENTER, NUMPADENTER, VK_RETURN, 0),
+ KEY_TRANS_ENTRY1(RCONTROL, RCTRL, RCONTROL, VK_RCONTROL, 0),
+ KEY_TRANS_ENTRY1(SLASH_PAD, KP_DIVIDE, DIVIDE, VK_DIVIDE, 0),
+ KEY_TRANS_ENTRY1(PRTSCR, PRINTSCREEN, SYSRQ, 0, 0),
+ KEY_TRANS_ENTRY1(RALT, RALT, RMENU, VK_RMENU, 0),
+ KEY_TRANS_ENTRY1(HOME, HOME, HOME, VK_HOME, 0),
+ KEY_TRANS_ENTRY1(UP, UP, UP, VK_UP, 0),
+ KEY_TRANS_ENTRY1(PGUP, PAGEUP, PRIOR, VK_PRIOR, 0),
+ KEY_TRANS_ENTRY1(LEFT, LEFT, LEFT, VK_LEFT, 0),
+ KEY_TRANS_ENTRY1(RIGHT, RIGHT, RIGHT, VK_RIGHT, 0),
+ KEY_TRANS_ENTRY1(END, END, END, VK_END, 0),
+ KEY_TRANS_ENTRY1(DOWN, DOWN, DOWN, VK_DOWN, 0),
+ KEY_TRANS_ENTRY1(PGDN, PAGEDOWN, NEXT, VK_NEXT, 0),
+ KEY_TRANS_ENTRY1(INSERT, INSERT, INSERT, VK_INSERT, 0),
+ KEY_TRANS_ENTRY0(DEL, DELETE, DELETE, VK_DELETE, 0, "DELETE"),
+ KEY_TRANS_ENTRY1(LWIN, LGUI, LWIN, VK_LWIN, 0),
+ KEY_TRANS_ENTRY1(RWIN, RGUI, RWIN, VK_RWIN, 0),
+ KEY_TRANS_ENTRY1(MENU, MENU, APPS, VK_APPS, 0),
+ KEY_TRANS_ENTRY1(PAUSE, PAUSE, PAUSE, VK_PAUSE, 0),
+ KEY_TRANS_ENTRY1(CANCEL, CANCEL, UNKNOWN, 0, 0),
+ KEY_TRANS_ENTRY1(BS_PAD, KP_BACKSPACE, UNKNOWN, 0, 0),
+ KEY_TRANS_ENTRY1(TAB_PAD, KP_TAB, UNKNOWN, 0, 0),
+ KEY_TRANS_ENTRY1(00_PAD, KP_00, UNKNOWN, 0, 0),
+ KEY_TRANS_ENTRY1(000_PAD, KP_000, UNKNOWN, 0, 0),
+ KEY_TRANS_ENTRY1(COMMA_PAD, KP_COMMA, NUMPADCOMMA, VK_SEPARATOR, 0),
+ KEY_TRANS_ENTRY1(EQUALS_PAD, KP_EQUALS, NUMPADEQUALS, VK_OEM_NEC_EQUAL, 0),
+
+ // keys that have no specific MAME input item IDs
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AUDIONEXT, NEXTTRACK, VK_MEDIA_NEXT_TRACK, 0, "AUDIONEXT"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AUDIOMUTE, MUTE, VK_VOLUME_MUTE, 0, "VOLUMEMUTE"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AUDIOPLAY, PLAYPAUSE, VK_MEDIA_PLAY_PAUSE, 0, "AUDIOPLAY"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AUDIOSTOP, MEDIASTOP, VK_MEDIA_STOP, 0, "AUDIOSTOP"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, VOLUMEDOWN, VOLUMEDOWN, VK_VOLUME_DOWN, 0, "VOLUMEDOWN"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, VOLUMEUP, VOLUMEUP, VK_VOLUME_UP, 0, "VOLUMEUP"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AC_HOME, WEBHOME, VK_BROWSER_HOME, 0, "NAVHOME"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AC_SEARCH, WEBSEARCH, VK_BROWSER_SEARCH, 0, "NAVSEARCH"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AC_BOOKMARKS, WEBFAVORITES, VK_BROWSER_FAVORITES, 0, "NAVFAVORITES"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AC_REFRESH, WEBREFRESH, VK_BROWSER_REFRESH, 0, "NAVREFRESH"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AC_STOP, WEBSTOP, VK_BROWSER_STOP, 0, "NAVSTOP"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AC_FORWARD, WEBFORWARD, VK_BROWSER_FORWARD, 0, "NAVFORWARD"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, AC_BACK, WEBBACK, VK_BROWSER_BACK, 0, "NAVBACK"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, MAIL, MAIL, VK_LAUNCH_MAIL, 0, "MAIL"),
+ KEY_TRANS_ENTRY0(OTHER_SWITCH, MEDIASELECT, MEDIASELECT, VK_LAUNCH_MEDIA_SELECT, 0, "MEDIASEL"),
+
+ // sentinel
+ KEY_TRANS_ENTRY0(INVALID, UNKNOWN, UNKNOWN, 0, 0, "INVALID")
};
// The private constructor to create the default instance
@@ -190,14 +192,18 @@ keyboard_trans_table::keyboard_trans_table()
m_table = s_default_table;
m_table_size = std::size(s_default_table);
}
-#else
+
+#else // defined(OSD_WINDOWS) || defined(OSD_SDL)
+
keyboard_trans_table::keyboard_trans_table()
{
m_table = nullptr;
m_table_size = 0;
}
-#endif
+#endif // defined(OSD_WINDOWS) || defined(OSD_SDL)
+
+
// public constructor to allow creation of non-default instances
keyboard_trans_table::keyboard_trans_table(std::unique_ptr<key_trans_entry[]> entries, unsigned int size)
{
@@ -248,11 +254,10 @@ int keyboard_trans_table::vkey_for_mame_code(input_code code) const
// only works for keyboard switches
if (code.device_class() == DEVICE_CLASS_KEYBOARD && code.item_class() == ITEM_CLASS_SWITCH)
{
- input_item_id id = code.item_id();
- int tablenum;
+ const input_item_id id = code.item_id();
// scan the table for a match
- for (tablenum = 0; tablenum < m_table_size; tablenum++)
+ for (int tablenum = 0; tablenum < m_table_size; tablenum++)
if (m_table[tablenum].mame_key == id)
return m_table[tablenum].virtual_key;
}
diff --git a/src/osd/modules/input/input_common.h b/src/osd/modules/input/input_common.h
index e767d2b07f2..28e53fb0ccb 100644
--- a/src/osd/modules/input/input_common.h
+++ b/src/osd/modules/input/input_common.h
@@ -47,155 +47,6 @@ enum
#define MAX_HATS 8
#define MAX_POV 4
-/****************************************************************************
-* DirectInput compatible keyboard scan codes
-****************************************************************************/
-#define KEY_UNKNOWN 0x00
-#define KEY_ESCAPE 0x01
-#define KEY_1 0x02
-#define KEY_2 0x03
-#define KEY_3 0x04
-#define KEY_4 0x05
-#define KEY_5 0x06
-#define KEY_6 0x07
-#define KEY_7 0x08
-#define KEY_8 0x09
-#define KEY_9 0x0A
-#define KEY_0 0x0B
-#define KEY_MINUS 0x0C /* - on main keyboard */
-#define KEY_EQUALS 0x0D
-#define KEY_BACK 0x0E /* backspace */
-#define KEY_TAB 0x0F
-#define KEY_Q 0x10
-#define KEY_W 0x11
-#define KEY_E 0x12
-#define KEY_R 0x13
-#define KEY_T 0x14
-#define KEY_Y 0x15
-#define KEY_U 0x16
-#define KEY_I 0x17
-#define KEY_O 0x18
-#define KEY_P 0x19
-#define KEY_LBRACKET 0x1A
-#define KEY_RBRACKET 0x1B
-#define KEY_RETURN 0x1C /* Enter on main keyboard */
-#define KEY_LCONTROL 0x1D
-#define KEY_A 0x1E
-#define KEY_S 0x1F
-#define KEY_D 0x20
-#define KEY_F 0x21
-#define KEY_G 0x22
-#define KEY_H 0x23
-#define KEY_J 0x24
-#define KEY_K 0x25
-#define KEY_L 0x26
-#define KEY_SEMICOLON 0x27
-#define KEY_APOSTROPHE 0x28
-#define KEY_GRAVE 0x29 /* accent grave */
-#define KEY_LSHIFT 0x2A
-#define KEY_BACKSLASH 0x2B
-#define KEY_Z 0x2C
-#define KEY_X 0x2D
-#define KEY_C 0x2E
-#define KEY_V 0x2F
-#define KEY_B 0x30
-#define KEY_N 0x31
-#define KEY_M 0x32
-#define KEY_COMMA 0x33
-#define KEY_PERIOD 0x34 /* . on main keyboard */
-#define KEY_SLASH 0x35 /* / on main keyboard */
-#define KEY_RSHIFT 0x36
-#define KEY_MULTIPLY 0x37 /* * on numeric keypad */
-#define KEY_LMENU 0x38 /* left Alt */
-#define KEY_SPACE 0x39
-#define KEY_CAPITAL 0x3A
-#define KEY_F1 0x3B
-#define KEY_F2 0x3C
-#define KEY_F3 0x3D
-#define KEY_F4 0x3E
-#define KEY_F5 0x3F
-#define KEY_F6 0x40
-#define KEY_F7 0x41
-#define KEY_F8 0x42
-#define KEY_F9 0x43
-#define KEY_F10 0x44
-#define KEY_NUMLOCK 0x45
-#define KEY_SCROLL 0x46 /* Scroll Lock */
-#define KEY_NUMPAD7 0x47
-#define KEY_NUMPAD8 0x48
-#define KEY_NUMPAD9 0x49
-#define KEY_SUBTRACT 0x4A /* - on numeric keypad */
-#define KEY_NUMPAD4 0x4B
-#define KEY_NUMPAD5 0x4C
-#define KEY_NUMPAD6 0x4D
-#define KEY_ADD 0x4E /* + on numeric keypad */
-#define KEY_NUMPAD1 0x4F
-#define KEY_NUMPAD2 0x50
-#define KEY_NUMPAD3 0x51
-#define KEY_NUMPAD0 0x52
-#define KEY_DECIMAL 0x53 /* . on numeric keypad */
-#define KEY_OEM_102 0x56 /* <> or \| on RT 102-key keyboard (Non-U.S.) */
-#define KEY_F11 0x57
-#define KEY_F12 0x58
-#define KEY_F13 0x64 /* (NEC PC98) */
-#define KEY_F14 0x65 /* (NEC PC98) */
-#define KEY_F15 0x66 /* (NEC PC98) */
-#define KEY_KANA 0x70 /* (Japanese keyboard) */
-#define KEY_ABNT_C1 0x73 /* /? on Brazilian keyboard */
-#define KEY_CONVERT 0x79 /* (Japanese keyboard) */
-#define KEY_NOCONVERT 0x7B /* (Japanese keyboard) */
-#define KEY_YEN 0x7D /* (Japanese keyboard) */
-#define KEY_ABNT_C2 0x7E /* Numpad . on Brazilian keyboard */
-#define KEY_NUMPADEQUALS 0x8D /* = on numeric keypad (NEC PC98) */
-#define KEY_PREVTRACK 0x90 /* Previous Track (DIK_CIRCUMFLEX on Japanese keyboard) */
-#define KEY_AT 0x91 /* (NEC PC98) */
-#define KEY_COLON 0x92 /* (NEC PC98) */
-#define KEY_UNDERLINE 0x93 /* (NEC PC98) */
-#define KEY_KANJI 0x94 /* (Japanese keyboard) */
-#define KEY_STOP 0x95 /* (NEC PC98) */
-#define KEY_AX 0x96 /* (Japan AX) */
-#define KEY_UNLABELED 0x97 /* (J3100) */
-#define KEY_NEXTTRACK 0x99 /* Next Track */
-#define KEY_NUMPADENTER 0x9C /* Enter on numeric keypad */
-#define KEY_RCONTROL 0x9D
-#define KEY_MUTE 0xA0 /* Mute */
-#define KEY_CALCULATOR 0xA1 /* Calculator */
-#define KEY_PLAYPAUSE 0xA2 /* Play / Pause */
-#define KEY_MEDIASTOP 0xA4 /* Media Stop */
-#define KEY_VOLUMEDOWN 0xAE /* Volume - */
-#define KEY_VOLUMEUP 0xB0 /* Volume + */
-#define KEY_WEBHOME 0xB2 /* Web home */
-#define KEY_NUMPADCOMMA 0xB3 /* , on numeric keypad (NEC PC98) */
-#define KEY_DIVIDE 0xB5 /* / on numeric keypad */
-#define KEY_SYSRQ 0xB7
-#define KEY_RMENU 0xB8 /* right Alt */
-#define KEY_PAUSE 0xC5 /* Pause */
-#define KEY_HOME 0xC7 /* Home on arrow keypad */
-#define KEY_UP 0xC8 /* UpArrow on arrow keypad */
-#define KEY_PRIOR 0xC9 /* PgUp on arrow keypad */
-#define KEY_LEFT 0xCB /* LeftArrow on arrow keypad */
-#define KEY_RIGHT 0xCD /* RightArrow on arrow keypad */
-#define KEY_END 0xCF /* End on arrow keypad */
-#define KEY_DOWN 0xD0 /* DownArrow on arrow keypad */
-#define KEY_NEXT 0xD1 /* PgDn on arrow keypad */
-#define KEY_INSERT 0xD2 /* Insert on arrow keypad */
-#define KEY_DELETE 0xD3 /* Delete on arrow keypad */
-#define KEY_LWIN 0xDB /* Left Windows key */
-#define KEY_RWIN 0xDC /* Right Windows key */
-#define KEY_APPS 0xDD /* AppMenu key */
-#define KEY_POWER 0xDE /* System Power */
-#define KEY_SLEEP 0xDF /* System Sleep */
-#define KEY_WAKE 0xE3 /* System Wake */
-#define KEY_WEBSEARCH 0xE5 /* Web Search */
-#define KEY_WEBFAVORITES 0xE6 /* Web Favorites */
-#define KEY_WEBREFRESH 0xE7 /* Web Refresh */
-#define KEY_WEBSTOP 0xE8 /* Web Stop */
-#define KEY_WEBFORWARD 0xE9 /* Web Forward */
-#define KEY_WEBBACK 0xEA /* Web Back */
-#define KEY_MYCOMPUTER 0xEB /* My Computer */
-#define KEY_MAIL 0xEC /* Mail */
-#define KEY_MEDIASELECT 0xED /* Media Select */
-
//============================================================
// device_info
@@ -342,7 +193,7 @@ struct key_trans_entry
int sdl_scancode;
#endif
#if defined(OSD_WINDOWS) || defined(SDLMAME_WIN32)
- int scan_code;
+ uint16_t scan_code;
unsigned char virtual_key;
#endif
diff --git a/src/osd/modules/input/input_dinput.cpp b/src/osd/modules/input/input_dinput.cpp
index eec5904b3ac..7732d610bba 100644
--- a/src/osd/modules/input/input_dinput.cpp
+++ b/src/osd/modules/input/input_dinput.cpp
@@ -194,7 +194,7 @@ void dinput_keyboard_device::configure(input_device &device)
{
// populate it
char defname[20];
- for (int keynum = 0; keynum < MAX_KEYS; keynum++)
+ for (unsigned keynum = 0; keynum < MAX_KEYS; keynum++)
{
input_item_id itemid = keyboard_trans_table::instance().map_di_scancode_to_itemid(keynum);
diff --git a/src/osd/modules/input/input_rawinput.cpp b/src/osd/modules/input/input_rawinput.cpp
index 3ee8e2d8f7e..3b5491fd09d 100644
--- a/src/osd/modules/input/input_rawinput.cpp
+++ b/src/osd/modules/input/input_rawinput.cpp
@@ -25,9 +25,11 @@
#include <algorithm>
#include <cassert>
+#include <chrono>
#include <functional>
#include <mutex>
#include <new>
+#include <utility>
// standard windows headers
#include <windows.h>
@@ -307,23 +309,75 @@ class rawinput_keyboard_device : public rawinput_device
public:
rawinput_keyboard_device(std::string &&name, std::string &&id, input_module &module, HANDLE handle) :
rawinput_device(std::move(name), std::move(id), module, handle),
+ m_pause_pressed(std::chrono::steady_clock::time_point::min()),
+ m_e1(0xffff),
m_keyboard({ { 0 } })
{
}
virtual void reset() override
{
+ m_pause_pressed = std::chrono::steady_clock::time_point::min();
memset(&m_keyboard, 0, sizeof(m_keyboard));
+ m_e1 = 0xffff;
+ }
+
+ virtual void poll(bool relative_reset) override
+ {
+ rawinput_device::poll(relative_reset);
+
+ if (m_keyboard.state[0x80 | 0x45] && (std::chrono::steady_clock::now() > (m_pause_pressed + std::chrono::milliseconds(30))))
+ m_keyboard.state[0x80 | 0x45] = 0x00;
}
virtual void process_event(RAWINPUT const &rawinput) override
{
// determine the full DIK-compatible scancode
- uint8_t scancode = (rawinput.data.keyboard.MakeCode & 0x7f) | ((rawinput.data.keyboard.Flags & RI_KEY_E0) ? 0x80 : 0x00);
+ uint8_t scancode;
- // scancode 0xaa is a special shift code we need to ignore
- if (scancode == 0xaa)
+ // the only thing that uses this is Pause
+ if (rawinput.data.keyboard.Flags & RI_KEY_E1)
+ {
+ m_e1 = rawinput.data.keyboard.MakeCode;
return;
+ }
+ else if (0xffff != m_e1)
+ {
+ auto const e1 = std::exchange(m_e1, 0xffff);
+ if (!(rawinput.data.keyboard.Flags & RI_KEY_E0))
+ {
+ if (((e1 & ~USHORT(0x80)) == 0x1d) && ((rawinput.data.keyboard.MakeCode & ~USHORT(0x80)) == 0x45))
+ {
+ if (rawinput.data.keyboard.Flags & RI_KEY_BREAK)
+ return; // RawInput generates a fake break immediately after the make - ignore it
+
+ m_pause_pressed = std::chrono::steady_clock::now();
+ scancode = 0x80 | 0x45;
+ }
+ else
+ {
+ return; // no idea
+ }
+ }
+ else
+ {
+ return; // shouldn't happen, ignore it
+ }
+ }
+ else
+ {
+ // strip bit 7 of the make code to work around dodgy drivers that set it for key up events
+ if (rawinput.data.keyboard.MakeCode & ~USHORT(0xff))
+ {
+ // won't fit in a byte along with the E0 flag
+ return;
+ }
+ scancode = (rawinput.data.keyboard.MakeCode & 0x7f) | ((rawinput.data.keyboard.Flags & RI_KEY_E0) ? 0x80 : 0x00);
+
+ // fake shift generated with cursor control and Ins/Del for compatibility with very old DOS software
+ if (scancode == 0xaa)
+ return;
+ }
// set or clear the key
m_keyboard.state[scancode] = (rawinput.data.keyboard.Flags & RI_KEY_BREAK) ? 0x00 : 0x80;
@@ -333,13 +387,20 @@ public:
{
keyboard_trans_table const &table = keyboard_trans_table::instance();
- for (int keynum = 0; keynum < MAX_KEYS; keynum++)
+ // FIXME: GetKeyNameTextW is for scan codes from WM_KEYDOWN, which aren't quite the same as DIK_* keycodes
+ // in particular, NumLock and Pause are reversed for US-style keyboard systems
+ for (unsigned keynum = 0; keynum < MAX_KEYS; keynum++)
{
input_item_id itemid = table.map_di_scancode_to_itemid(keynum);
WCHAR keyname[100];
// generate the name
- if (GetKeyNameTextW(((keynum & 0x7f) << 16) | ((keynum & 0x80) << 17), keyname, std::size(keyname)) == 0)
+ // FIXME: GetKeyNameText gives bogus names for media keys and various other things
+ // in many cases it ignores the "extended" bit and returns the key name corresponding to the scan code alone
+ LONG lparam = ((keynum & 0x7f) << 16) | ((keynum & 0x80) << 17);
+ if ((keynum & 0x7f) == 0x45)
+ lparam ^= 0x0100'0000; // horrid hack
+ if (GetKeyNameTextW(lparam, keyname, std::size(keyname)) == 0)
_snwprintf(keyname, std::size(keyname), L"Scan%03d", keynum);
std::string name = text::from_wstring(keyname);
@@ -354,6 +415,8 @@ public:
}
private:
+ std::chrono::steady_clock::time_point m_pause_pressed;
+ uint16_t m_e1;
keyboard_state m_keyboard;
};
diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp
index 1eaed99f16b..fb478511a99 100644
--- a/src/osd/modules/input/input_sdl.cpp
+++ b/src/osd/modules/input/input_sdl.cpp
@@ -617,13 +617,8 @@ public:
for (int keynum = 0; m_trans_table[keynum].mame_key != ITEM_ID_INVALID; keynum++)
{
input_item_id itemid = m_trans_table[keynum].mame_key;
-
- // generate the default / modified name
- char defname[20];
- snprintf(defname, sizeof(defname) - 1, "%s", m_trans_table[keynum].ui_name);
-
device.add_item(
- defname,
+ m_trans_table[keynum].ui_name,
std::string_view(),
itemid,
generic_button_get_state<s32>,
@@ -1977,8 +1972,7 @@ class sdl_keyboard_module : public sdl_input_module<sdl_keyboard_device>
{
public:
sdl_keyboard_module() :
- sdl_input_module<sdl_keyboard_device>(OSD_KEYBOARDINPUT_PROVIDER, "sdl"),
- m_key_trans_table(nullptr)
+ sdl_input_module<sdl_keyboard_device>(OSD_KEYBOARDINPUT_PROVIDER, "sdl")
{
}
@@ -1993,7 +1987,7 @@ public:
subscribe(osd(), event_types);
// Read our keymap and store a pointer to our table
- m_key_trans_table = sdlinput_read_keymap();
+ sdlinput_read_keymap();
osd_printf_verbose("Keyboard: Start initialization\n");
@@ -2009,12 +2003,27 @@ public:
}
private:
- keyboard_trans_table *sdlinput_read_keymap()
+ void sdlinput_read_keymap()
{
keyboard_trans_table &default_table = keyboard_trans_table::instance();
+ // Allocate a block of translation entries big enough to hold what's in the default table
+ auto key_trans_entries = std::make_unique<key_trans_entry []>(default_table.size());
+
+ // copy the elements from the default table and ask SDL for key names
+ for (int i = 0; i < default_table.size(); i++)
+ {
+ key_trans_entries[i] = default_table[i];
+ char const *const name = SDL_GetScancodeName(SDL_Scancode(default_table[i].sdl_scancode));
+ if (name && *name)
+ key_trans_entries[i].ui_name = name;
+ }
+
+ // Allocate the trans table to be associated with the machine so we don't have to free it
+ m_key_trans_table = std::make_unique<keyboard_trans_table>(std::move(key_trans_entries), default_table.size());
+
if (!options()->bool_value(SDLOPTION_KEYMAP))
- return &default_table;
+ return;
const char *const keymap_filename = dynamic_cast<sdl_options const &>(*options()).keymap_file();
osd_printf_verbose("Keymap: Start reading keymap_file %s\n", keymap_filename);
@@ -2023,19 +2032,9 @@ private:
if (!keymap_file)
{
osd_printf_warning("Keymap: Unable to open keymap %s, using default\n", keymap_filename);
- return &default_table;
+ return;
}
- // Allocate a block of translation entries big enough to hold what's in the default table
- auto key_trans_entries = std::make_unique<key_trans_entry[]>(default_table.size());
-
- // copy the elements from the default table
- for (int i = 0; i < default_table.size(); i++)
- key_trans_entries[i] = default_table[i];
-
- // Allocate the trans table to be associated with the machine so we don't have to free it
- m_custom_table = std::make_unique<keyboard_trans_table>(std::move(key_trans_entries), default_table.size());
-
int line = 1;
int sdl2section = 0;
while (!feof(keymap_file))
@@ -2068,7 +2067,7 @@ private:
if (sk >= 0 && index >= 0)
{
- key_trans_entry &entry = (*m_custom_table)[index];
+ key_trans_entry &entry = (*m_key_trans_table)[index];
entry.sdl_scancode = sk;
entry.ui_name = const_cast<char *>(m_ui_names.emplace_back(kns).c_str());
osd_printf_verbose("Keymap: Mapped <%s> to <%s> with ui-text <%s>\n", sks, mks, kns);
@@ -2083,12 +2082,9 @@ private:
}
fclose(keymap_file);
osd_printf_verbose("Keymap: Processed %d lines\n", line);
-
- return m_custom_table.get();
}
- keyboard_trans_table *m_key_trans_table;
- std::unique_ptr<keyboard_trans_table> m_custom_table;
+ std::unique_ptr<keyboard_trans_table> m_key_trans_table;
std::list<std::string> m_ui_names;
};
diff --git a/src/osd/modules/input/input_win32.cpp b/src/osd/modules/input/input_win32.cpp
index 6919c8d5c42..3803bc2a180 100644
--- a/src/osd/modules/input/input_win32.cpp
+++ b/src/osd/modules/input/input_win32.cpp
@@ -59,6 +59,8 @@ public:
TCHAR keyname[100];
// generate the name
+ // FIXME: GetKeyNameText gives bogus names for media keys and various other things
+ // in many cases it ignores the "extended" bit and returns the key name corresponding to the scan code alone
if (GetKeyNameText(((keynum & 0x7f) << 16) | ((keynum & 0x80) << 17), keyname, std::size(keyname)) == 0)
_sntprintf(keyname, std::size(keyname), TEXT("Scan%03d"), keynum);
std::string name = text::from_tstring(keyname);
diff --git a/src/osd/windows/window.cpp b/src/osd/windows/window.cpp
index 387a7f6daba..87467a7e06f 100644
--- a/src/osd/windows/window.cpp
+++ b/src/osd/windows/window.cpp
@@ -31,10 +31,10 @@
#include "modules/monitor/monitor_common.h"
-#define NOT_ALREADY_DOWN(x) (x & 0x40000000) == 0
+#define NOT_ALREADY_DOWN(x) ((x & 0x40000000) == 0)
#define SCAN_CODE(x) ((x >> 16) & 0xff)
-#define IS_EXTENDED(x) (0x01000000 & x)
-#define MAKE_DI_SCAN(scan, isextended) (scan & 0x7f) | (isextended ? 0x80 : 0x00)
+#define IS_EXTENDED(x) ((x >> 24) & 0x01)
+#define MAKE_DI_SCAN(scan, isextended) ((scan & 0x7f) | (isextended ? 0x80 : 0x00))
#define WINOSD(machine) downcast<windows_osd_interface*>(&machine.osd())
//============================================================