Skip to content

Commit

Permalink
Add support for multimedia keys
Browse files Browse the repository at this point in the history
Extended RETROK_ values with 18 new items, commonly found on
"multimedia" keyboards.

Mapping added for SDL, X11, Wayland, dinput, winraw keymaps.

Keyboard tester function of Remote Retropad extended to cover new keys.

One fix in Android mapping for libretro#12986
  • Loading branch information
zoltanvb committed May 6, 2024
1 parent 711bf39 commit 59413dd
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cores/libretro-net-retropad/net_retropad_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ static void NETRETROPAD_CORE_PREFIX(update_keyboard_cb)(bool down, unsigned keyc
(keycode >= 123 && keycode < 127) ||
(keycode == 272) ||
(keycode >= 294 && keycode < 297) ||
(keycode >= 309 && keycode < 323))
(keycode >= 309 && keycode < RETROK_LAST))
{
snprintf(buf, sizeof(buf), "Key pressed: %d",keycode);
message.msg = buf;
Expand Down Expand Up @@ -586,7 +586,7 @@ static void open_UDP_socket()
socket_target_t in_target;

if (s && s != SOCKET_ERROR)
close(s);
socket_close(s);

s = socket_create(
"retropad",
Expand Down
12 changes: 6 additions & 6 deletions cores/libretro-net-retropad/remotepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ static uint8_t keyboard_body[] =
/* 134 */ 2, 0, 255,
/* 135 */ 2, 0, 255,
/* 136 */ 2, 0, 255,
/* 137 */ 1, 255,
/* 138 */ 1, 255,
/* 139 */ 1, 255,
/* 140 */ 1, 255,
/* 137 */ 2, 0, 255,
/* 138 */ 2, 0, 255,
/* 139 */ 2, 0, 255,
/* 140 */ 2, 0, 255,
/* 141 */ 1, 255,
};

Expand Down Expand Up @@ -587,8 +587,8 @@ static uint16_t keyboard_buttons[] =
/* 135 */ 41, 1, 126, 10, 2, 272, 10, 2, 294, 10, 2, 295, 10, 2, 296, 10, 2, 309, 10, 2, 310, 10, 2, 311, 10, 2, 312, 10, 2, 313, 10, 2, 315, 10, 2, 316, 10, 2, 317, 10, 2, 318, 10, 2, 319, 10, 2, 320, 10, 2, 321, 10, 2, 322, 10, 2, 314, 10, 2, 0, 10, 16,
/* 136 */ 1, 255,
/* 137 */ 1, 255,
/* 138 */ 1, 255,
/* 139 */ 1, 255,
/* 138 */ 37, 1, 324, 10, 2, 325, 10, 2, 326, 10, 2, 327, 10, 2, 328, 10, 2, 329, 10, 2, 330, 10, 2, 331, 10, 2, 332, 10, 2, 333, 10, 2, 334, 10, 2, 335, 10, 2, 336, 10, 2, 337, 10, 2, 338, 10, 2, 339, 10, 2, 340, 10, 2, 341, 10, 40,
/* 139 */ 37, 1, 324, 10, 2, 325, 10, 2, 326, 10, 2, 327, 10, 2, 328, 10, 2, 329, 10, 2, 330, 10, 2, 331, 10, 2, 332, 10, 2, 333, 10, 2, 334, 10, 2, 335, 10, 2, 336, 10, 2, 337, 10, 2, 338, 10, 2, 339, 10, 2, 340, 10, 2, 341, 10, 40,
/* 140 */ 1, 255,
/* 141 */ 1, 255,
};
Expand Down
20 changes: 20 additions & 0 deletions input/include/xfree86_keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ enum xfvk_key
XFVK_FK23 = 201,
XFVK_FK24 = 202,

/* Multimedia keys */
XFVK_MUTE = 121,
XFVK_VOUP = 122,
XFVK_VODN = 123,
XFVK_BSTP = 136,
XFVK_APP1 = 156,
XFVK_APP2 = 157,
XFVK_MAIL = 163,
XFVK_FAVO = 164,
XFVK_BBAC = 166,
XFVK_BFWD = 167,
XFVK_CDNX = 171,
XFVK_PLAY = 172,
XFVK_CDPR = 173,
XFVK_CDST = 174,
XVFK_HOMP = 180,
XFVK_REFR = 181,
XFVK_BSEA = 225,
XFVK_MDIA = 234,

XFVK_LAST,
XFVK_DUMMY = 255
};
Expand Down
2 changes: 1 addition & 1 deletion input/input_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#define MAX_INPUT_DEVICES 16

#define RARCH_MAX_KEYS 137
#define RARCH_MAX_KEYS 155

#define RARCH_FIRST_CUSTOM_BIND 16
#define RARCH_FIRST_LIGHTGUN_BIND RARCH_ANALOG_BIND_LIST_END
Expand Down
127 changes: 125 additions & 2 deletions input/input_keymaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
#ifdef __APPLE__
#include "drivers_keyboard/keyboard_event_apple.h"
#endif

/* TODO: ensure that for UI display, menu_driver.c key_descriptors are shown instead of this */
const struct input_key_map input_config_key_map[] = {
{ "left", RETROK_LEFT },
{ "right", RETROK_RIGHT },
Expand Down Expand Up @@ -203,6 +203,25 @@ const struct input_key_map input_config_key_map[] = {
{ "clear", RETROK_CLEAR },
{ "oem102", RETROK_OEM_102 },

{ "back", RETROK_BROWSER_BACK },
{ "forward", RETROK_BROWSER_FORWARD },
{ "refresh", RETROK_BROWSER_REFRESH },
{ "bstop", RETROK_BROWSER_STOP },
{ "search", RETROK_BROWSER_SEARCH },
{ "favorites", RETROK_BROWSER_FAVORITES },
{ "homepage", RETROK_BROWSER_HOME },
{ "mute", RETROK_VOLUME_MUTE },
{ "volumedown", RETROK_VOLUME_DOWN },
{ "volumeup", RETROK_VOLUME_UP },
{ "next", RETROK_MEDIA_NEXT },
{ "prev", RETROK_MEDIA_PREV },
{ "stop", RETROK_MEDIA_STOP },
{ "play", RETROK_MEDIA_PLAY_PAUSE },
{ "email", RETROK_LAUNCH_MAIL },
{ "media", RETROK_LAUNCH_MEDIA },
{ "app1", RETROK_LAUNCH_APP1 },
{ "app2", RETROK_LAUNCH_APP2 },

{ "nul", RETROK_UNKNOWN },
{ NULL, RETROK_UNKNOWN },
};
Expand Down Expand Up @@ -778,6 +797,27 @@ const struct rarch_key_map rarch_key_map_sdl[] = {
#endif
{ SDLK_UNDO, RETROK_UNDO },

#ifdef HAVE_SDL2
{ SDLK_AUDIONEXT, RETROK_MEDIA_NEXT },
{ SDLK_AUDIOPREV, RETROK_MEDIA_PREV },
{ SDLK_AUDIOSTOP, RETROK_MEDIA_STOP },
{ SDLK_AUDIOPLAY, RETROK_MEDIA_PLAY_PAUSE },
{ SDLK_AUDIOMUTE, RETROK_VOLUME_MUTE },
{ SDLK_MEDIASELECT, RETROK_LAUNCH_MEDIA },
{ SDLK_MAIL, RETROK_LAUNCH_MAIL },
{ SDLK_CALCULATOR, RETROK_LAUNCH_APP2 },
{ SDLK_COMPUTER, RETROK_LAUNCH_APP1 },
{ SDLK_AC_SEARCH, RETROK_BROWSER_SEARCH },
{ SDLK_AC_HOME, RETROK_BROWSER_HOME },
{ SDLK_AC_BACK, RETROK_BROWSER_BACK },
{ SDLK_AC_FORWARD, RETROK_BROWSER_FORWARD },
{ SDLK_AC_STOP, RETROK_BROWSER_STOP },
{ SDLK_AC_REFRESH, RETROK_BROWSER_REFRESH },
{ SDLK_AC_BOOKMARKS, RETROK_BROWSER_FAVORITES },
{ SDLK_VOLUMEUP, RETROK_VOLUME_UP },
{ SDLK_VOLUMEDOWN, RETROK_VOLUME_DOWN },
#endif

{ 0, RETROK_UNKNOWN },
};
#endif
Expand Down Expand Up @@ -891,6 +931,30 @@ const struct rarch_key_map rarch_key_map_dinput[] = {
{ DIK_CAPSLOCK, RETROK_CAPSLOCK },
{ DIK_NUMLOCK, RETROK_NUMLOCK },
{ DIK_OEM_102, RETROK_OEM_102 },
/* dinput.h included to MXE seems to carry only the alternate name circumflex */
#ifdef DIK_PREVTRACK
{ DIK_PREVTRACK, RETROK_MEDIA_PREV },
#else
{ DIK_CIRCUMFLEX, RETROK_MEDIA_PREV },
#endif
{ DIK_NEXTTRACK, RETROK_MEDIA_NEXT },
{ DIK_MUTE, RETROK_VOLUME_MUTE },
{ DIK_CALCULATOR, RETROK_LAUNCH_APP2 },
{ DIK_PLAYPAUSE, RETROK_MEDIA_PLAY_PAUSE },
{ DIK_MEDIASTOP, RETROK_MEDIA_STOP },
{ DIK_VOLUMEDOWN, RETROK_VOLUME_DOWN },
{ DIK_VOLUMEUP, RETROK_VOLUME_UP },
{ DIK_WEBHOME, RETROK_BROWSER_HOME },
{ DIK_WEBSEARCH, RETROK_BROWSER_SEARCH },
{ DIK_WEBFAVORITES, RETROK_BROWSER_FAVORITES },
{ DIK_WEBREFRESH, RETROK_BROWSER_REFRESH },
{ DIK_WEBSTOP, RETROK_BROWSER_STOP },
{ DIK_WEBFORWARD, RETROK_BROWSER_FORWARD },
{ DIK_WEBBACK, RETROK_BROWSER_BACK },
{ DIK_MYCOMPUTER, RETROK_LAUNCH_APP1 },
{ DIK_MAIL, RETROK_LAUNCH_MAIL },
{ DIK_MEDIASELECT, RETROK_LAUNCH_MEDIA },

{ 0, RETROK_UNKNOWN },
};
#endif
Expand Down Expand Up @@ -1125,6 +1189,25 @@ const struct rarch_key_map rarch_key_map_x11[] = {
{ XFVK_KP0, RETROK_KP0 },
{ XFVK_KPDL, RETROK_KP_PERIOD },
{ XFVK_KPEQ, RETROK_KP_EQUALS },

{ XFVK_MUTE, RETROK_VOLUME_MUTE },
{ XFVK_VOUP, RETROK_VOLUME_UP },
{ XFVK_VODN, RETROK_VOLUME_DOWN },
{ XFVK_APP1, RETROK_LAUNCH_APP1 },
{ XFVK_APP2, RETROK_LAUNCH_APP2 },
{ XFVK_MAIL, RETROK_LAUNCH_MAIL },
{ XFVK_FAVO, RETROK_BROWSER_FAVORITES },
{ XFVK_BBAC, RETROK_BROWSER_BACK },
{ XFVK_BFWD, RETROK_BROWSER_FORWARD },
{ XFVK_CDNX, RETROK_MEDIA_NEXT },
{ XFVK_PLAY, RETROK_MEDIA_PLAY_PAUSE },
{ XFVK_CDPR, RETROK_MEDIA_PREV },
{ XFVK_CDST, RETROK_MEDIA_STOP },
{ XVFK_HOMP, RETROK_BROWSER_HOME },
{ XFVK_REFR, RETROK_BROWSER_REFRESH },
{ XFVK_BSTP, RETROK_BROWSER_STOP },
{ XFVK_BSEA, RETROK_BROWSER_SEARCH },
{ XFVK_MDIA, RETROK_LAUNCH_MEDIA },

{ 0, RETROK_UNKNOWN },
};
Expand Down Expand Up @@ -1279,6 +1362,28 @@ const struct rarch_key_map rarch_key_map_linux[] = {
#endif
{ KEY_UNDO, RETROK_UNDO },
{ KEY_102ND, RETROK_OEM_102 },

#ifndef ANDROID
{ KEY_MUTE, RETROK_VOLUME_MUTE },
{ KEY_VOLUMEDOWN, RETROK_VOLUME_DOWN },
{ KEY_VOLUMEUP, RETROK_VOLUME_UP },
{ KEY_STOP, RETROK_BROWSER_STOP },
{ KEY_PROG1, RETROK_LAUNCH_APP1 },
{ KEY_PROG2, RETROK_LAUNCH_APP2 },
{ KEY_MAIL, RETROK_LAUNCH_MAIL },
{ KEY_BOOKMARKS, RETROK_BROWSER_FAVORITES },
{ KEY_BACK, RETROK_BROWSER_BACK },
{ KEY_FORWARD, RETROK_BROWSER_FORWARD },
{ KEY_NEXTSONG, RETROK_MEDIA_NEXT },
{ KEY_PLAYPAUSE, RETROK_MEDIA_PLAY_PAUSE },
{ KEY_PREVIOUSSONG, RETROK_MEDIA_PREV },
{ KEY_STOPCD, RETROK_MEDIA_STOP },
{ KEY_HOMEPAGE, RETROK_BROWSER_HOME },
{ KEY_REFRESH, RETROK_BROWSER_REFRESH },
{ KEY_SEARCH, RETROK_BROWSER_SEARCH },
{ KEY_MEDIA, RETROK_LAUNCH_MEDIA },
#endif

{ 0, RETROK_UNKNOWN },
};
#endif
Expand Down Expand Up @@ -1343,7 +1448,7 @@ const struct rarch_key_map rarch_key_map_android[] = {
{ AKEYCODE_X, RETROK_x },
{ AKEYCODE_Y, RETROK_y },
{ AKEYCODE_Z, RETROK_z },
{ AKEYCODE_DEL, RETROK_DELETE },
{ AKEYCODE_FORWARD_DEL, RETROK_DELETE },
{ AKEYCODE_NUMPAD_0, RETROK_KP0 },
{ AKEYCODE_NUMPAD_1, RETROK_KP1 },
{ AKEYCODE_NUMPAD_2, RETROK_KP2 },
Expand Down Expand Up @@ -1952,6 +2057,24 @@ const struct rarch_key_map rarch_key_map_winraw[] = {
{ SC_SLASH, RETROK_SLASH },
{ SC_APOSTROPHE, RETROK_QUOTE },
{ SC_ANGLEBRACKET, RETROK_OEM_102 },
{ SC_BROWSER_SEARCH, RETROK_BROWSER_SEARCH },
{ SC_BROWSER_FAVORITES, RETROK_BROWSER_FAVORITES },
{ SC_BROWSER_REFRESH, RETROK_BROWSER_REFRESH },
{ SC_BROWSER_STOP, RETROK_BROWSER_STOP },
{ SC_BROWSER_FORWARD, RETROK_BROWSER_FORWARD },
{ SC_BROWSER_BACK, RETROK_BROWSER_BACK },
{ SC_LAUNCH_EMAIL, RETROK_LAUNCH_MAIL },
{ SC_LAUNCH_MEDIA, RETROK_LAUNCH_MEDIA },
{ SC_MEDIA_PREV, RETROK_MEDIA_PREV },
{ SC_MEDIA_NEXT, RETROK_MEDIA_NEXT },
{ SC_VOLUME_MUTE, RETROK_VOLUME_MUTE },
{ SC_LAUNCH_APP1, RETROK_LAUNCH_APP1 },
{ SC_LAUNCH_APP2, RETROK_LAUNCH_APP2 },
{ SC_MEDIA_PLAY, RETROK_MEDIA_PLAY_PAUSE },
{ SC_MEDIA_STOP, RETROK_MEDIA_STOP },
{ SC_VOLUME_DOWN, RETROK_VOLUME_DOWN },
{ SC_VOLUME_UP, RETROK_VOLUME_UP },
{ SC_BROWSER_HOME, RETROK_BROWSER_HOME },
{ 0, RETROK_UNKNOWN }
};
#endif
Expand Down
19 changes: 19 additions & 0 deletions libretro-common/include/libretro.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,25 @@ enum retro_key
RETROK_UNDO = 322,
RETROK_OEM_102 = 323,

RETROK_BROWSER_BACK = 324,
RETROK_BROWSER_FORWARD = 325,
RETROK_BROWSER_REFRESH = 326,
RETROK_BROWSER_STOP = 327,
RETROK_BROWSER_SEARCH = 328,
RETROK_BROWSER_FAVORITES = 329,
RETROK_BROWSER_HOME = 330,
RETROK_VOLUME_MUTE = 331,
RETROK_VOLUME_DOWN = 332,
RETROK_VOLUME_UP = 333,
RETROK_MEDIA_NEXT = 334,
RETROK_MEDIA_PREV = 335,
RETROK_MEDIA_STOP = 336,
RETROK_MEDIA_PLAY_PAUSE = 337,
RETROK_LAUNCH_MAIL = 338,
RETROK_LAUNCH_MEDIA = 339,
RETROK_LAUNCH_APP1 = 340,
RETROK_LAUNCH_APP2 = 341,

RETROK_LAST,

RETROK_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
Expand Down
22 changes: 21 additions & 1 deletion menu/menu_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,27 @@ struct key_desc key_descriptors[RARCH_MAX_KEYS] =
{RETROK_POWER, "Power"},
{RETROK_EURO, {-30, -126, -84, 0}}, /* "�" */
{RETROK_UNDO, "Undo"},
{RETROK_OEM_102, "OEM-102"}
{RETROK_OEM_102, "OEM-102"},

{RETROK_BROWSER_BACK, "Back"},
{RETROK_BROWSER_FORWARD, "Forward"},
{RETROK_BROWSER_REFRESH, "Refresh"},
{RETROK_BROWSER_STOP, "Stop"},
{RETROK_BROWSER_SEARCH, "Search"},
{RETROK_BROWSER_FAVORITES, "Favorites"},
{RETROK_BROWSER_HOME, "Home Page"},
{RETROK_VOLUME_MUTE, "Mute"},
{RETROK_VOLUME_DOWN, "Volume Up"},
{RETROK_VOLUME_UP, "Volume Down"},
{RETROK_MEDIA_NEXT, "Next Track"},
{RETROK_MEDIA_PREV, "Previous Track"},
{RETROK_MEDIA_STOP, "Media Stop"},
{RETROK_MEDIA_PLAY_PAUSE, "Media Play"},
{RETROK_LAUNCH_MAIL, "Launch Email"},
{RETROK_LAUNCH_MEDIA, "Launch Media"},
{RETROK_LAUNCH_APP1, "Launch App1"},
{RETROK_LAUNCH_APP2, "Launch App2"}

};

static void *null_menu_init(void **userdata, bool video_is_threaded)
Expand Down

0 comments on commit 59413dd

Please sign in to comment.