mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-27 21:27:12 +00:00
254 lines
6.5 KiB
C
254 lines
6.5 KiB
C
/* RetroArch - A frontend for libretro.
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
|
*
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "input_context.h"
|
|
#include "input_keymaps.h"
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include "../general.h"
|
|
|
|
rarch_joypad_driver_t *joypad_drivers[] = {
|
|
#ifdef __CELLOS_LV2__
|
|
&ps3_joypad,
|
|
#endif
|
|
#ifdef HAVE_WINXINPUT
|
|
&winxinput_joypad,
|
|
#endif
|
|
#ifdef GEKKO
|
|
&gx_joypad,
|
|
#endif
|
|
#ifdef _XBOX
|
|
&xdk_joypad,
|
|
#endif
|
|
#ifdef PSP
|
|
&psp_joypad,
|
|
#endif
|
|
#ifdef HAVE_DINPUT
|
|
&dinput_joypad,
|
|
#endif
|
|
#ifdef HAVE_UDEV
|
|
&udev_joypad,
|
|
#endif
|
|
#if defined(__linux) && !defined(ANDROID)
|
|
&linuxraw_joypad,
|
|
#endif
|
|
#ifdef HAVE_PARPORT
|
|
&parport_joypad,
|
|
#endif
|
|
#ifdef ANDROID
|
|
&android_joypad,
|
|
#endif
|
|
#if defined(HAVE_SDL) || defined(HAVE_SDL2)
|
|
&sdl_joypad,
|
|
#endif
|
|
#ifdef __MACH__
|
|
#ifdef HAVE_HID
|
|
&apple_hid_joypad,
|
|
#endif
|
|
#ifdef IOS
|
|
&apple_ios_joypad,
|
|
#endif
|
|
#endif
|
|
#ifdef __QNX__
|
|
&qnx_joypad,
|
|
#endif
|
|
&null_joypad,
|
|
NULL,
|
|
};
|
|
|
|
const struct input_key_map input_config_key_map[] = {
|
|
{ "left", RETROK_LEFT },
|
|
{ "right", RETROK_RIGHT },
|
|
{ "up", RETROK_UP },
|
|
{ "down", RETROK_DOWN },
|
|
{ "enter", RETROK_RETURN },
|
|
{ "kp_enter", RETROK_KP_ENTER },
|
|
{ "tab", RETROK_TAB },
|
|
{ "insert", RETROK_INSERT },
|
|
{ "del", RETROK_DELETE },
|
|
{ "end", RETROK_END },
|
|
{ "home", RETROK_HOME },
|
|
{ "rshift", RETROK_RSHIFT },
|
|
{ "shift", RETROK_LSHIFT },
|
|
{ "ctrl", RETROK_LCTRL },
|
|
{ "alt", RETROK_LALT },
|
|
{ "space", RETROK_SPACE },
|
|
{ "escape", RETROK_ESCAPE },
|
|
{ "add", RETROK_KP_PLUS },
|
|
{ "subtract", RETROK_KP_MINUS },
|
|
{ "kp_plus", RETROK_KP_PLUS },
|
|
{ "kp_minus", RETROK_KP_MINUS },
|
|
{ "f1", RETROK_F1 },
|
|
{ "f2", RETROK_F2 },
|
|
{ "f3", RETROK_F3 },
|
|
{ "f4", RETROK_F4 },
|
|
{ "f5", RETROK_F5 },
|
|
{ "f6", RETROK_F6 },
|
|
{ "f7", RETROK_F7 },
|
|
{ "f8", RETROK_F8 },
|
|
{ "f9", RETROK_F9 },
|
|
{ "f10", RETROK_F10 },
|
|
{ "f11", RETROK_F11 },
|
|
{ "f12", RETROK_F12 },
|
|
{ "num0", RETROK_0 },
|
|
{ "num1", RETROK_1 },
|
|
{ "num2", RETROK_2 },
|
|
{ "num3", RETROK_3 },
|
|
{ "num4", RETROK_4 },
|
|
{ "num5", RETROK_5 },
|
|
{ "num6", RETROK_6 },
|
|
{ "num7", RETROK_7 },
|
|
{ "num8", RETROK_8 },
|
|
{ "num9", RETROK_9 },
|
|
{ "pageup", RETROK_PAGEUP },
|
|
{ "pagedown", RETROK_PAGEDOWN },
|
|
{ "keypad0", RETROK_KP0 },
|
|
{ "keypad1", RETROK_KP1 },
|
|
{ "keypad2", RETROK_KP2 },
|
|
{ "keypad3", RETROK_KP3 },
|
|
{ "keypad4", RETROK_KP4 },
|
|
{ "keypad5", RETROK_KP5 },
|
|
{ "keypad6", RETROK_KP6 },
|
|
{ "keypad7", RETROK_KP7 },
|
|
{ "keypad8", RETROK_KP8 },
|
|
{ "keypad9", RETROK_KP9 },
|
|
{ "period", RETROK_PERIOD },
|
|
{ "capslock", RETROK_CAPSLOCK },
|
|
{ "numlock", RETROK_NUMLOCK },
|
|
{ "backspace", RETROK_BACKSPACE },
|
|
{ "multiply", RETROK_KP_MULTIPLY },
|
|
{ "divide", RETROK_KP_DIVIDE },
|
|
{ "print_screen", RETROK_PRINT },
|
|
{ "scroll_lock", RETROK_SCROLLOCK },
|
|
{ "tilde", RETROK_BACKQUOTE },
|
|
{ "backquote", RETROK_BACKQUOTE },
|
|
{ "pause", RETROK_PAUSE },
|
|
|
|
/* Keys that weren't mappable before */
|
|
{ "quote", RETROK_QUOTE },
|
|
{ "comma", RETROK_COMMA },
|
|
{ "minus", RETROK_MINUS },
|
|
{ "slash", RETROK_SLASH },
|
|
{ "semicolon", RETROK_SEMICOLON },
|
|
{ "equals", RETROK_EQUALS },
|
|
{ "leftbracket", RETROK_LEFTBRACKET },
|
|
{ "backslash", RETROK_BACKSLASH },
|
|
{ "rightbracket", RETROK_RIGHTBRACKET },
|
|
{ "kp_period", RETROK_KP_PERIOD },
|
|
{ "kp_equals", RETROK_KP_EQUALS },
|
|
{ "rctrl", RETROK_RCTRL },
|
|
{ "ralt", RETROK_RALT },
|
|
|
|
/* Keys not referenced in any keyboard mapping
|
|
* (except perhaps rarch_key_map_apple_hid) */
|
|
{ "caret", RETROK_CARET },
|
|
{ "underscore", RETROK_UNDERSCORE },
|
|
{ "exclaim", RETROK_EXCLAIM },
|
|
{ "quotedbl", RETROK_QUOTEDBL },
|
|
{ "hash", RETROK_HASH },
|
|
{ "dollar", RETROK_DOLLAR },
|
|
{ "ampersand", RETROK_AMPERSAND },
|
|
{ "leftparen", RETROK_LEFTPAREN },
|
|
{ "rightparen", RETROK_RIGHTPAREN },
|
|
{ "asterisk", RETROK_ASTERISK },
|
|
{ "plus", RETROK_PLUS },
|
|
{ "colon", RETROK_COLON },
|
|
{ "less", RETROK_LESS },
|
|
{ "greater", RETROK_GREATER },
|
|
{ "question", RETROK_QUESTION },
|
|
{ "at", RETROK_AT },
|
|
|
|
{ "f13", RETROK_F13 },
|
|
{ "f14", RETROK_F14 },
|
|
{ "f15", RETROK_F15 },
|
|
|
|
{ "rmeta", RETROK_RMETA },
|
|
{ "lmeta", RETROK_LMETA },
|
|
{ "lsuper", RETROK_LSUPER },
|
|
{ "rsuper", RETROK_RSUPER },
|
|
{ "mode", RETROK_MODE },
|
|
{ "compose", RETROK_COMPOSE },
|
|
|
|
{ "help", RETROK_HELP },
|
|
{ "sysreq", RETROK_SYSREQ },
|
|
{ "break", RETROK_BREAK },
|
|
{ "menu", RETROK_MENU },
|
|
{ "power", RETROK_POWER },
|
|
{ "euro", RETROK_EURO },
|
|
{ "undo", RETROK_UNDO },
|
|
{ "clear", RETROK_CLEAR },
|
|
|
|
{ "nul", RETROK_UNKNOWN },
|
|
{ NULL, RETROK_UNKNOWN },
|
|
};
|
|
|
|
static enum retro_key find_rk_bind(const char *str)
|
|
{
|
|
size_t i;
|
|
for (i = 0; input_config_key_map[i].str; i++)
|
|
{
|
|
if (strcasecmp(input_config_key_map[i].str, str) == 0)
|
|
return input_config_key_map[i].key;
|
|
}
|
|
|
|
RARCH_WARN("Key name %s not found.\n", str);
|
|
return RETROK_UNKNOWN;
|
|
}
|
|
|
|
enum retro_key input_translate_str_to_rk(const char *str)
|
|
{
|
|
if (strlen(str) == 1 && isalpha(*str))
|
|
return (enum retro_key)(RETROK_a + (tolower(*str) - (int)'a'));
|
|
return find_rk_bind(str);
|
|
}
|
|
|
|
const rarch_joypad_driver_t *input_joypad_init_driver(const char *ident)
|
|
{
|
|
unsigned i;
|
|
if (!ident || !*ident)
|
|
return input_joypad_init_first();
|
|
|
|
for (i = 0; joypad_drivers[i]; i++)
|
|
{
|
|
if (strcmp(ident, joypad_drivers[i]->ident) == 0
|
|
&& joypad_drivers[i]->init())
|
|
{
|
|
RARCH_LOG("Found joypad driver: \"%s\".\n",
|
|
joypad_drivers[i]->ident);
|
|
return joypad_drivers[i];
|
|
}
|
|
}
|
|
|
|
return input_joypad_init_first();
|
|
}
|
|
|
|
const rarch_joypad_driver_t *input_joypad_init_first(void)
|
|
{
|
|
unsigned i;
|
|
for (i = 0; joypad_drivers[i]; i++)
|
|
{
|
|
if (joypad_drivers[i]->init())
|
|
{
|
|
RARCH_LOG("Found joypad driver: \"%s\".\n",
|
|
joypad_drivers[i]->ident);
|
|
return joypad_drivers[i];
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|