diff --git a/apple/OSX/settings.m b/apple/OSX/settings.m index 650983a4c2..9059dd9fb2 100644 --- a/apple/OSX/settings.m +++ b/apple/OSX/settings.m @@ -242,43 +242,18 @@ static const char* get_axis_name(const rarch_setting_t* setting) - (void)checkBind:(NSTimer*)send { - // Keyboard - for (int i = 0; apple_key_name_map[i].hid_id; i++) - { - if (g_current_input_data.keys[apple_key_name_map[i].hid_id]) - { - BINDFOR(*_setting).key = input_translate_keysym_to_rk(apple_key_name_map[i].hid_id); - [self dismissBinder]; - return; - } - } + int32_t value = 0; - // Joystick - if (g_current_input_data.pad_buttons[0]) - { - for (int i = 0; i != 32; i ++) - { - if (g_current_input_data.pad_buttons[0] & (1 << i)) - { - BINDFOR(*_setting).joykey = i; - [self dismissBinder]; - return; - } - } - } + if ((value = apple_input_find_any_key())) + BINDFOR(*_setting).key = input_translate_keysym_to_rk(value); + else if ((value = apple_input_find_any_button(0)) >= 0) + BINDFOR(*_setting).joykey = value; + else if ((value = apple_input_find_any_axis(0))) + BINDFOR(*_setting).joyaxis = (value > 0) ? AXIS_POS(value - 1) : AXIS_NEG(value - 1); + else + return; - // Pad Axis - for (int i = 0; i < 4; i++) - { - int16_t value = g_current_input_data.pad_axis[0][i]; - - if (abs(value) > 0x4000) - { - BINDFOR(*_setting).joyaxis = (value > 0x1000) ? AXIS_POS(i) : AXIS_NEG(i); - [self dismissBinder]; - break; - } - } + [self dismissBinder]; } - (IBAction)doGetBind:(id)sender diff --git a/apple/common/apple_input.c b/apple/common/apple_input.c index 07a1bdecfa..152acb13a0 100644 --- a/apple/common/apple_input.c +++ b/apple/common/apple_input.c @@ -22,14 +22,14 @@ #include "general.h" #include "driver.h" +#include "keycode.inc" + extern const rarch_joypad_driver_t apple_joypad; static const rarch_joypad_driver_t* const g_joydriver = &apple_joypad; apple_input_data_t g_current_input_data; apple_input_data_t g_polled_input_data; -static const struct rarch_key_map rarch_key_map_hidusage[]; - #ifdef OSX // Taken from https://github.com/depp/keycode, check keycode.h for license const unsigned char MAC_NATIVE_TO_HID[128] = { 4, 22, 7, 9, 11, 10, 29, 27, 6, 25,255, 5, 20, 26, 8, 21, @@ -101,6 +101,42 @@ void apple_input_handle_key_event(unsigned keycode, bool down) g_current_input_data.keys[keycode] = down; } + +int32_t apple_input_find_any_key() +{ + for (int i = 0; apple_key_name_map[i].hid_id; i++) + if (g_current_input_data.keys[apple_key_name_map[i].hid_id]) + return apple_key_name_map[i].hid_id; + + return 0; +} + +int32_t apple_input_find_any_button(uint32_t port) +{ + uint32_t buttons = g_current_input_data.pad_buttons[port] | + ((port == 0) ? apple_input_get_icade_buttons() : 0); + + if (g_current_input_data.pad_buttons[port]) + for (int i = 0; i != 32; i ++) + if (buttons & (1 << i)) + return i; + + return -1; +} + +int32_t apple_input_find_any_axis(uint32_t port) +{ + for (int i = 0; i < 4; i++) + { + int16_t value = g_current_input_data.pad_axis[port][i]; + + if (abs(value) > 0x4000) + return (value < 0) ? -(i + 1) : i + 1; + } + + return 0; +} + // Game thread interface static bool apple_key_pressed(enum retro_key key) { @@ -118,7 +154,7 @@ static bool apple_is_pressed(unsigned port_num, const struct retro_keybind *bind // Exported input driver static void *apple_input_init(void) { - input_init_keyboard_lut(rarch_key_map_hidusage); + input_init_keyboard_lut(apple_key_map_hidusage); memset(&g_polled_input_data, 0, sizeof(g_polled_input_data)); return (void*)-1; } @@ -273,150 +309,3 @@ const input_driver_t input_apple = { apple_input_set_keybinds, "apple_input", }; - - -// Key table -#include "keycode.h" -static const struct rarch_key_map rarch_key_map_hidusage[] = { - { KEY_Delete, RETROK_BACKSPACE }, - { KEY_Tab, RETROK_TAB }, -// RETROK_CLEAR }, - { KEY_Enter, RETROK_RETURN }, - { KEY_Pause, RETROK_PAUSE }, - { KEY_Escape, RETROK_ESCAPE }, - { KEY_Space, RETROK_SPACE }, -// RETROK_EXCLAIM }, -// RETROK_QUOTEDBL }, -// RETROK_HASH }, -// RETROK_DOLLAR }, -// RETROK_AMPERSAND }, - { KEY_Quote, RETROK_QUOTE }, -// RETROK_LEFTPAREN }, -// RETROK_RIGHTPAREN }, -// RETROK_ASTERISK }, -// RETROK_PLUS }, - { KEY_Comma, RETROK_COMMA }, - { KEY_Minus, RETROK_MINUS }, - { KEY_Period, RETROK_PERIOD }, - { KEY_Slash, RETROK_SLASH }, - { KEY_0, RETROK_0 }, - { KEY_1, RETROK_1 }, - { KEY_2, RETROK_2 }, - { KEY_3, RETROK_3 }, - { KEY_4, RETROK_4 }, - { KEY_5, RETROK_5 }, - { KEY_6, RETROK_6 }, - { KEY_7, RETROK_7 }, - { KEY_8, RETROK_8 }, - { KEY_9, RETROK_9 }, -// RETROK_COLON }, - { KEY_Semicolon, RETROK_SEMICOLON }, -// RETROK_LESS }, - { KEY_Equals, RETROK_EQUALS }, -// RETROK_GREATER }, -// RETROK_QUESTION }, -// RETROK_AT }, - { KEY_LeftBracket, RETROK_LEFTBRACKET }, - { KEY_Backslash, RETROK_BACKSLASH }, - { KEY_RightBracket, RETROK_RIGHTBRACKET }, -// RETROK_CARET }, -// RETROK_UNDERSCORE }, - { KEY_Grave, RETROK_BACKQUOTE }, - { KEY_A, RETROK_a }, - { KEY_B, RETROK_b }, - { KEY_C, RETROK_c }, - { KEY_D, RETROK_d }, - { KEY_E, RETROK_e }, - { KEY_F, RETROK_f }, - { KEY_G, RETROK_g }, - { KEY_H, RETROK_h }, - { KEY_I, RETROK_i }, - { KEY_J, RETROK_j }, - { KEY_K, RETROK_k }, - { KEY_L, RETROK_l }, - { KEY_M, RETROK_m }, - { KEY_N, RETROK_n }, - { KEY_O, RETROK_o }, - { KEY_P, RETROK_p }, - { KEY_Q, RETROK_q }, - { KEY_R, RETROK_r }, - { KEY_S, RETROK_s }, - { KEY_T, RETROK_t }, - { KEY_U, RETROK_u }, - { KEY_V, RETROK_v }, - { KEY_W, RETROK_w }, - { KEY_X, RETROK_x }, - { KEY_Y, RETROK_y }, - { KEY_Z, RETROK_z }, - { KEY_DeleteForward, RETROK_DELETE }, - - { KP_0, RETROK_KP0 }, - { KP_1, RETROK_KP1 }, - { KP_2, RETROK_KP2 }, - { KP_3, RETROK_KP3 }, - { KP_4, RETROK_KP4 }, - { KP_5, RETROK_KP5 }, - { KP_6, RETROK_KP6 }, - { KP_7, RETROK_KP7 }, - { KP_8, RETROK_KP8 }, - { KP_9, RETROK_KP9 }, - { KP_Point, RETROK_KP_PERIOD }, - { KP_Divide, RETROK_KP_DIVIDE }, - { KP_Multiply, RETROK_KP_MULTIPLY }, - { KP_Subtract, RETROK_KP_MINUS }, - { KP_Add, RETROK_KP_PLUS }, - { KP_Enter, RETROK_KP_ENTER }, - { KP_Equals, RETROK_KP_EQUALS }, - - { KEY_Up, RETROK_UP }, - { KEY_Down, RETROK_DOWN }, - { KEY_Right, RETROK_RIGHT }, - { KEY_Left, RETROK_LEFT }, - { KEY_Insert, RETROK_INSERT }, - { KEY_Home, RETROK_HOME }, - { KEY_End, RETROK_END }, - { KEY_PageUp, RETROK_PAGEUP }, - { KEY_PageDown, RETROK_PAGEDOWN }, - - { KEY_F1, RETROK_F1 }, - { KEY_F2, RETROK_F2 }, - { KEY_F3, RETROK_F3 }, - { KEY_F4, RETROK_F4 }, - { KEY_F5, RETROK_F5 }, - { KEY_F6, RETROK_F6 }, - { KEY_F7, RETROK_F7 }, - { KEY_F8, RETROK_F8 }, - { KEY_F9, RETROK_F9 }, - { KEY_F10, RETROK_F10 }, - { KEY_F11, RETROK_F11 }, - { KEY_F12, RETROK_F12 }, - { KEY_F13, RETROK_F13 }, - { KEY_F14, RETROK_F14 }, - { KEY_F15, RETROK_F15 }, - -// RETROK_NUMLOCK }, - { KEY_CapsLock, RETROK_CAPSLOCK }, -// RETROK_SCROLLOCK }, - { KEY_RightShift, RETROK_RSHIFT }, - { KEY_LeftShift, RETROK_LSHIFT }, - { KEY_RightControl, RETROK_RCTRL }, - { KEY_LeftControl, RETROK_LCTRL }, - { KEY_RightAlt, RETROK_RALT }, - { KEY_LeftAlt, RETROK_LALT }, - { KEY_RightGUI, RETROK_RMETA }, - { KEY_LeftGUI, RETROK_RMETA }, -// RETROK_LSUPER }, -// RETROK_RSUPER }, -// RETROK_MODE }, -// RETROK_COMPOSE }, - -// RETROK_HELP }, - { KEY_PrintScreen, RETROK_PRINT }, -// RETROK_SYSREQ }, -// RETROK_BREAK }, - { KEY_Menu, RETROK_MENU }, -// RETROK_POWER }, -// RETROK_EURO }, -// RETROK_UNDO }, - { 0, RETROK_UNKNOWN } -}; diff --git a/apple/common/apple_input.h b/apple/common/apple_input.h index 4a1ee13788..8d95746597 100644 --- a/apple/common/apple_input.h +++ b/apple/common/apple_input.h @@ -50,4 +50,8 @@ void apple_input_enable_icade(bool on); uint32_t apple_input_get_icade_buttons(); void apple_input_handle_key_event(unsigned keycode, bool down); +extern int32_t apple_input_find_any_key(); +extern int32_t apple_input_find_any_button(uint32_t port); +extern int32_t apple_input_find_any_axis(uint32_t port); + #endif diff --git a/apple/common/keycode.h b/apple/common/keycode.h index e24fe023d4..f0b8a1219a 100644 --- a/apple/common/keycode.h +++ b/apple/common/keycode.h @@ -153,4 +153,21 @@ enum { KEY_RightAlt = 230, KEY_RightGUI = 231 }; + +// + +#include "input/input_common.h" // < For rarch_key_map + +struct apple_key_name_map_entry +{ + const char* const keyname; + const uint32_t hid_id; +}; + +extern const struct apple_key_name_map_entry apple_key_name_map[]; +extern const struct rarch_key_map apple_key_map_hidusage[]; + + +const char* apple_keycode_hidusage_to_name(uint32_t hid_usage); + #endif diff --git a/apple/common/keycode.inc b/apple/common/keycode.inc new file mode 100644 index 0000000000..f9d7363113 --- /dev/null +++ b/apple/common/keycode.inc @@ -0,0 +1,222 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2013 - Jason Fetters + * + * 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 . + */ + +#include "keycode.h" + +const struct apple_key_name_map_entry apple_key_name_map[] = +{ + { "left", KEY_Left }, { "right", KEY_Right }, + { "up", KEY_Up }, { "down", KEY_Down }, + { "enter", KEY_Enter }, { "kp_enter", KP_Enter }, + { "space", KEY_Space }, { "tab", KEY_Tab }, + { "shift", KEY_LeftShift }, { "rshift", KEY_RightShift }, + { "ctrl", KEY_LeftControl }, { "alt", KEY_LeftAlt }, + { "escape", KEY_Escape }, { "backspace", KEY_DeleteForward }, + { "backquote", KEY_Grave }, { "pause", KEY_Pause }, + + { "f1", KEY_F1 }, { "f2", KEY_F2 }, + { "f3", KEY_F3 }, { "f4", KEY_F4 }, + { "f5", KEY_F5 }, { "f6", KEY_F6 }, + { "f7", KEY_F7 }, { "f8", KEY_F8 }, + { "f9", KEY_F9 }, { "f10", KEY_F10 }, + { "f11", KEY_F11 }, { "f12", KEY_F12 }, + + { "num0", KEY_0 }, { "num1", KEY_1 }, + { "num2", KEY_2 }, { "num3", KEY_3 }, + { "num4", KEY_4 }, { "num5", KEY_5 }, + { "num6", KEY_6 }, { "num7", KEY_7 }, + { "num8", KEY_8 }, { "num9", KEY_9 }, + + { "insert", KEY_Insert }, { "del", KEY_DeleteForward }, + { "home", KEY_Home }, { "end", KEY_End }, + { "pageup", KEY_PageUp }, { "pagedown", KEY_PageDown }, + + { "add", KP_Add }, { "subtract", KP_Subtract }, + { "multiply", KP_Multiply }, { "divide", KP_Divide }, + { "keypad0", KP_0 }, { "keypad1", KP_1 }, + { "keypad2", KP_2 }, { "keypad3", KP_3 }, + { "keypad4", KP_4 }, { "keypad5", KP_5 }, + { "keypad6", KP_6 }, { "keypad7", KP_7 }, + { "keypad8", KP_8 }, { "keypad9", KP_9 }, + + { "period", KEY_Period }, { "capslock", KEY_CapsLock }, + { "numlock", KP_NumLock }, { "print_screen", KEY_PrintScreen }, + { "scroll_lock", KEY_ScrollLock }, + + { "a", KEY_A }, { "b", KEY_B }, { "c", KEY_C }, { "d", KEY_D }, + { "e", KEY_E }, { "f", KEY_F }, { "g", KEY_G }, { "h", KEY_H }, + { "i", KEY_I }, { "j", KEY_J }, { "k", KEY_K }, { "l", KEY_L }, + { "m", KEY_M }, { "n", KEY_N }, { "o", KEY_O }, { "p", KEY_P }, + { "q", KEY_Q }, { "r", KEY_R }, { "s", KEY_S }, { "t", KEY_T }, + { "u", KEY_U }, { "v", KEY_V }, { "w", KEY_W }, { "x", KEY_X }, + { "y", KEY_Y }, { "z", KEY_Z }, + + { "nul", 0x00}, +}; + +const struct rarch_key_map apple_key_map_hidusage[] = +{ + { KEY_Delete, RETROK_BACKSPACE }, + { KEY_Tab, RETROK_TAB }, +// RETROK_CLEAR }, + { KEY_Enter, RETROK_RETURN }, + { KEY_Pause, RETROK_PAUSE }, + { KEY_Escape, RETROK_ESCAPE }, + { KEY_Space, RETROK_SPACE }, +// RETROK_EXCLAIM }, +// RETROK_QUOTEDBL }, +// RETROK_HASH }, +// RETROK_DOLLAR }, +// RETROK_AMPERSAND }, + { KEY_Quote, RETROK_QUOTE }, +// RETROK_LEFTPAREN }, +// RETROK_RIGHTPAREN }, +// RETROK_ASTERISK }, +// RETROK_PLUS }, + { KEY_Comma, RETROK_COMMA }, + { KEY_Minus, RETROK_MINUS }, + { KEY_Period, RETROK_PERIOD }, + { KEY_Slash, RETROK_SLASH }, + { KEY_0, RETROK_0 }, + { KEY_1, RETROK_1 }, + { KEY_2, RETROK_2 }, + { KEY_3, RETROK_3 }, + { KEY_4, RETROK_4 }, + { KEY_5, RETROK_5 }, + { KEY_6, RETROK_6 }, + { KEY_7, RETROK_7 }, + { KEY_8, RETROK_8 }, + { KEY_9, RETROK_9 }, +// RETROK_COLON }, + { KEY_Semicolon, RETROK_SEMICOLON }, +// RETROK_LESS }, + { KEY_Equals, RETROK_EQUALS }, +// RETROK_GREATER }, +// RETROK_QUESTION }, +// RETROK_AT }, + { KEY_LeftBracket, RETROK_LEFTBRACKET }, + { KEY_Backslash, RETROK_BACKSLASH }, + { KEY_RightBracket, RETROK_RIGHTBRACKET }, +// RETROK_CARET }, +// RETROK_UNDERSCORE }, + { KEY_Grave, RETROK_BACKQUOTE }, + { KEY_A, RETROK_a }, + { KEY_B, RETROK_b }, + { KEY_C, RETROK_c }, + { KEY_D, RETROK_d }, + { KEY_E, RETROK_e }, + { KEY_F, RETROK_f }, + { KEY_G, RETROK_g }, + { KEY_H, RETROK_h }, + { KEY_I, RETROK_i }, + { KEY_J, RETROK_j }, + { KEY_K, RETROK_k }, + { KEY_L, RETROK_l }, + { KEY_M, RETROK_m }, + { KEY_N, RETROK_n }, + { KEY_O, RETROK_o }, + { KEY_P, RETROK_p }, + { KEY_Q, RETROK_q }, + { KEY_R, RETROK_r }, + { KEY_S, RETROK_s }, + { KEY_T, RETROK_t }, + { KEY_U, RETROK_u }, + { KEY_V, RETROK_v }, + { KEY_W, RETROK_w }, + { KEY_X, RETROK_x }, + { KEY_Y, RETROK_y }, + { KEY_Z, RETROK_z }, + { KEY_DeleteForward, RETROK_DELETE }, + + { KP_0, RETROK_KP0 }, + { KP_1, RETROK_KP1 }, + { KP_2, RETROK_KP2 }, + { KP_3, RETROK_KP3 }, + { KP_4, RETROK_KP4 }, + { KP_5, RETROK_KP5 }, + { KP_6, RETROK_KP6 }, + { KP_7, RETROK_KP7 }, + { KP_8, RETROK_KP8 }, + { KP_9, RETROK_KP9 }, + { KP_Point, RETROK_KP_PERIOD }, + { KP_Divide, RETROK_KP_DIVIDE }, + { KP_Multiply, RETROK_KP_MULTIPLY }, + { KP_Subtract, RETROK_KP_MINUS }, + { KP_Add, RETROK_KP_PLUS }, + { KP_Enter, RETROK_KP_ENTER }, + { KP_Equals, RETROK_KP_EQUALS }, + + { KEY_Up, RETROK_UP }, + { KEY_Down, RETROK_DOWN }, + { KEY_Right, RETROK_RIGHT }, + { KEY_Left, RETROK_LEFT }, + { KEY_Insert, RETROK_INSERT }, + { KEY_Home, RETROK_HOME }, + { KEY_End, RETROK_END }, + { KEY_PageUp, RETROK_PAGEUP }, + { KEY_PageDown, RETROK_PAGEDOWN }, + + { KEY_F1, RETROK_F1 }, + { KEY_F2, RETROK_F2 }, + { KEY_F3, RETROK_F3 }, + { KEY_F4, RETROK_F4 }, + { KEY_F5, RETROK_F5 }, + { KEY_F6, RETROK_F6 }, + { KEY_F7, RETROK_F7 }, + { KEY_F8, RETROK_F8 }, + { KEY_F9, RETROK_F9 }, + { KEY_F10, RETROK_F10 }, + { KEY_F11, RETROK_F11 }, + { KEY_F12, RETROK_F12 }, + { KEY_F13, RETROK_F13 }, + { KEY_F14, RETROK_F14 }, + { KEY_F15, RETROK_F15 }, + +// RETROK_NUMLOCK }, + { KEY_CapsLock, RETROK_CAPSLOCK }, +// RETROK_SCROLLOCK }, + { KEY_RightShift, RETROK_RSHIFT }, + { KEY_LeftShift, RETROK_LSHIFT }, + { KEY_RightControl, RETROK_RCTRL }, + { KEY_LeftControl, RETROK_LCTRL }, + { KEY_RightAlt, RETROK_RALT }, + { KEY_LeftAlt, RETROK_LALT }, + { KEY_RightGUI, RETROK_RMETA }, + { KEY_LeftGUI, RETROK_RMETA }, +// RETROK_LSUPER }, +// RETROK_RSUPER }, +// RETROK_MODE }, +// RETROK_COMPOSE }, + +// RETROK_HELP }, + { KEY_PrintScreen, RETROK_PRINT }, +// RETROK_SYSREQ }, +// RETROK_BREAK }, + { KEY_Menu, RETROK_MENU }, +// RETROK_POWER }, +// RETROK_EURO }, +// RETROK_UNDO }, + { 0, RETROK_UNKNOWN } +}; + + +const char* apple_keycode_hidusage_to_name(uint32_t hid_usage) +{ + for (int i = 0; apple_key_name_map[i].hid_id; i ++) + if (apple_key_name_map[i].hid_id == hid_usage) + return apple_key_name_map[i].keyname; + + return "nul"; +} diff --git a/apple/common/setting_data.h b/apple/common/setting_data.h index 0f91eb5825..208fb8ea73 100644 --- a/apple/common/setting_data.h +++ b/apple/common/setting_data.h @@ -343,58 +343,5 @@ const rarch_setting_t setting_data[] = // Keyboard #include "keycode.h" -static const struct -{ - const char* const keyname; - const uint32_t hid_id; -} apple_key_name_map[] = { - { "left", KEY_Left }, { "right", KEY_Right }, - { "up", KEY_Up }, { "down", KEY_Down }, - { "enter", KEY_Enter }, { "kp_enter", KP_Enter }, - { "space", KEY_Space }, { "tab", KEY_Tab }, - { "shift", KEY_LeftShift }, { "rshift", KEY_RightShift }, - { "ctrl", KEY_LeftControl }, { "alt", KEY_LeftAlt }, - { "escape", KEY_Escape }, { "backspace", KEY_DeleteForward }, - { "backquote", KEY_Grave }, { "pause", KEY_Pause }, - - { "f1", KEY_F1 }, { "f2", KEY_F2 }, - { "f3", KEY_F3 }, { "f4", KEY_F4 }, - { "f5", KEY_F5 }, { "f6", KEY_F6 }, - { "f7", KEY_F7 }, { "f8", KEY_F8 }, - { "f9", KEY_F9 }, { "f10", KEY_F10 }, - { "f11", KEY_F11 }, { "f12", KEY_F12 }, - - { "num0", KEY_0 }, { "num1", KEY_1 }, - { "num2", KEY_2 }, { "num3", KEY_3 }, - { "num4", KEY_4 }, { "num5", KEY_5 }, - { "num6", KEY_6 }, { "num7", KEY_7 }, - { "num8", KEY_8 }, { "num9", KEY_9 }, - - { "insert", KEY_Insert }, { "del", KEY_DeleteForward }, - { "home", KEY_Home }, { "end", KEY_End }, - { "pageup", KEY_PageUp }, { "pagedown", KEY_PageDown }, - - { "add", KP_Add }, { "subtract", KP_Subtract }, - { "multiply", KP_Multiply }, { "divide", KP_Divide }, - { "keypad0", KP_0 }, { "keypad1", KP_1 }, - { "keypad2", KP_2 }, { "keypad3", KP_3 }, - { "keypad4", KP_4 }, { "keypad5", KP_5 }, - { "keypad6", KP_6 }, { "keypad7", KP_7 }, - { "keypad8", KP_8 }, { "keypad9", KP_9 }, - - { "period", KEY_Period }, { "capslock", KEY_CapsLock }, - { "numlock", KP_NumLock }, { "print_screen", KEY_PrintScreen }, - { "scroll_lock", KEY_ScrollLock }, - - { "a", KEY_A }, { "b", KEY_B }, { "c", KEY_C }, { "d", KEY_D }, - { "e", KEY_E }, { "f", KEY_F }, { "g", KEY_G }, { "h", KEY_H }, - { "i", KEY_I }, { "j", KEY_J }, { "k", KEY_K }, { "l", KEY_L }, - { "m", KEY_M }, { "n", KEY_N }, { "o", KEY_O }, { "p", KEY_P }, - { "q", KEY_Q }, { "r", KEY_R }, { "s", KEY_S }, { "t", KEY_T }, - { "u", KEY_U }, { "v", KEY_V }, { "w", KEY_W }, { "x", KEY_X }, - { "y", KEY_Y }, { "z", KEY_Z }, - - { "nul", 0x00}, -}; #endif \ No newline at end of file diff --git a/apple/iOS/settings.m b/apple/iOS/settings.m index a0fbd31ff6..e36c6181ad 100644 --- a/apple/iOS/settings.m +++ b/apple/iOS/settings.m @@ -840,97 +840,18 @@ static void bluetooth_option_changed(RASettingData* setting) - (void)checkInput { - // Keyboard - static const struct - { - const char* const keyname; - const uint32_t hid_id; - } ios_key_name_map[] = { - { "left", KEY_Left }, { "right", KEY_Right }, - { "up", KEY_Up }, { "down", KEY_Down }, - { "enter", KEY_Enter }, { "kp_enter", KP_Enter }, - { "space", KEY_Space }, { "tab", KEY_Tab }, - { "shift", KEY_LeftShift }, { "rshift", KEY_RightShift }, - { "ctrl", KEY_LeftControl }, { "alt", KEY_LeftAlt }, - { "escape", KEY_Escape }, { "backspace", KEY_DeleteForward }, - { "backquote", KEY_Grave }, { "pause", KEY_Pause }, + int32_t value = 0; - { "f1", KEY_F1 }, { "f2", KEY_F2 }, - { "f3", KEY_F3 }, { "f4", KEY_F4 }, - { "f5", KEY_F5 }, { "f6", KEY_F6 }, - { "f7", KEY_F7 }, { "f8", KEY_F8 }, - { "f9", KEY_F9 }, { "f10", KEY_F10 }, - { "f11", KEY_F11 }, { "f12", KEY_F12 }, - - { "num0", KEY_0 }, { "num1", KEY_1 }, - { "num2", KEY_2 }, { "num3", KEY_3 }, - { "num4", KEY_4 }, { "num5", KEY_5 }, - { "num6", KEY_6 }, { "num7", KEY_7 }, - { "num8", KEY_8 }, { "num9", KEY_9 }, + if ((value = apple_input_find_any_key())) + _value->value = [NSString stringWithUTF8String:apple_keycode_hidusage_to_name(value)]; + else if ((value = apple_input_find_any_button(0)) >= 0) + _value->button_bind = [NSString stringWithFormat:@"%d", value]; + else if ((value = apple_input_find_any_axis(0))) + _value->axis_bind = [NSString stringWithFormat:@"%s%d", (value > 0) ? "+" : "-", value - 1]; + else + return; - { "insert", KEY_Insert }, { "del", KEY_DeleteForward }, - { "home", KEY_Home }, { "end", KEY_End }, - { "pageup", KEY_PageUp }, { "pagedown", KEY_PageDown }, - - { "add", KP_Add }, { "subtract", KP_Subtract }, - { "multiply", KP_Multiply }, { "divide", KP_Divide }, - { "keypad0", KP_0 }, { "keypad1", KP_1 }, - { "keypad2", KP_2 }, { "keypad3", KP_3 }, - { "keypad4", KP_4 }, { "keypad5", KP_5 }, - { "keypad6", KP_6 }, { "keypad7", KP_7 }, - { "keypad8", KP_8 }, { "keypad9", KP_9 }, - - { "period", KEY_Period }, { "capslock", KEY_CapsLock }, - { "numlock", KP_NumLock }, { "print_screen", KEY_PrintScreen }, - { "scroll_lock", KEY_ScrollLock }, - - { "a", KEY_A }, { "b", KEY_B }, { "c", KEY_C }, { "d", KEY_D }, - { "e", KEY_E }, { "f", KEY_F }, { "g", KEY_G }, { "h", KEY_H }, - { "i", KEY_I }, { "j", KEY_J }, { "k", KEY_K }, { "l", KEY_L }, - { "m", KEY_M }, { "n", KEY_N }, { "o", KEY_O }, { "p", KEY_P }, - { "q", KEY_Q }, { "r", KEY_R }, { "s", KEY_S }, { "t", KEY_T }, - { "u", KEY_U }, { "v", KEY_V }, { "w", KEY_W }, { "x", KEY_X }, - { "y", KEY_Y }, { "z", KEY_Z }, - - { "nul", 0x00}, - }; - - for (int i = 0; ios_key_name_map[i].hid_id; i++) - { - if (g_current_input_data.keys[ios_key_name_map[i].hid_id]) - { - _value->value = [NSString stringWithUTF8String:ios_key_name_map[i].keyname]; - [self finish]; - return; - } - } - - // Pad Buttons - uint32_t buttons = g_current_input_data.pad_buttons[_value->player] | - ((_value->player == 0) ? apple_input_get_icade_buttons() : 0); - - for (int i = 0; buttons && i < sizeof(buttons) * 8; i++) - { - if (buttons & (1 << i)) - { - _value->button_bind = [NSString stringWithFormat:@"%d", i]; - [self finish]; - return; - } - } - - // Pad Axis - for (int i = 0; i < 4; i++) - { - int16_t value = g_current_input_data.pad_axis[_value->player][i]; - - if (abs(value) > 0x1000) - { - _value->axis_bind = [NSString stringWithFormat:@"%s%d", (value > 0x1000) ? "+" : "-", i]; - [self finish]; - break; - } - } + [self finish]; } @end