ios: Start adding bluetooth keyboard remapping support.

This commit is contained in:
meancoot 2013-02-12 16:01:11 -05:00
parent cf78e13e6e
commit e3447803a4
2 changed files with 299 additions and 31 deletions

View File

@ -21,7 +21,190 @@
#include "../../general.h"
#include "../../driver.h"
/*
0x00 Reserved (no event indicated)
0x01 Keyboard ErrorRollOver
0x02 Keyboard POSTFail
0x03 Keyboard ErrorUndefined
0x2D Keyboard - and (underscore)
0x2E Keyboard = and +
0x2F Keyboard [ and {
0x30 Keyboard ] and }
0x31 Keyboard \ and |
0x32 Keyboard Non-US # and ~
0x33 Keyboard ; and :
0x34 Keyboard ' and "
0x36 Keyboard, and <
0x37 Keyboard . and >
0x38 Keyboard / and ?
0x39 Keyboard Caps Lock
0x46 Keyboard PrintScreen
0x47 Keyboard Scroll Lock
0x4C Keyboard Delete Forward
0x53 Keypad Num Lock and Clear
0x63 Keypad . and Delete
0x64 Keyboard Non-US \ and |
0x65 Keyboard Application
0x66 Keyboard Power
0x67 Keypad =
0x68 Keyboard F13
0x69 Keyboard F14
0x6A Keyboard F15
0x6B Keyboard F16
0x6C Keyboard F17
0x6D Keyboard F18
0x6E Keyboard F19
0x6F Keyboard F20
0x70 Keyboard F21
0x71 Keyboard F22
0x72 Keyboard F23
0x73 Keyboard F24
0x74 Keyboard Execute
0x75 Keyboard Help
0x76 Keyboard Menu
0x77 Keyboard Select
0x78 Keyboard Stop
0x79 Keyboard Again
0x7A Keyboard Undo
0x7B Keyboard Cut
0x7C Keyboard Copy
0x7D Keyboard Paste
0x7E Keyboard Find
0x7F Keyboard Mute
0x80 Keyboard Volume Up
0x81 Keyboard Volume Down
0x82 Keyboard Locking Caps Lock
0x83 Keyboard Locking Num Lock
0x84 Keyboard Locking Scroll Lock
0x85 Keypad Comma
0x86 Keypad Equal Sign
0x87 Keyboard International1
0x88 Keyboard International2
0x89 Keyboard International3
0x8A Keyboard International4
0x8B Keyboard International5
0x8C Keyboard International6
0x8D Keyboard International7
0x8E Keyboard International8
0x8F Keyboard International9
0x90 Keyboard LANG1
0x91 Keyboard LANG2
0x92 Keyboard LANG3
0x93 Keyboard LANG4
0x94 Keyboard LANG5
0x95 Keyboard LANG6
0x96 Keyboard LANG7
0x97 Keyboard LANG8
0x98 Keyboard LANG9
0x99 Keyboard Alternate Erase
0x9A Keyboard SysReq/Attention
0x9B Keyboard Cancel
0x9C Keyboard Clear
0x9D Keyboard Prior
0x9E Keyboard Return
0x9F Keyboard Separator
0xA0 Keyboard Out
0xA1 Keyboard Oper
0xA2 Keyboard Clear/Again
0xA3 Keyboard CrSel/Props
0xA4 Keyboard ExSel
0xE3 Keyboard Left GUI
0xE4 Keyboard RightControl
0xE6 Keyboard RightAlt
0xE7 Keyboard Right GUI
*/
// This may be useful for other platforms too
static const struct rarch_key_map rarch_key_map_hidusage[] = {
{ 0x50, RETROK_LEFT },
{ 0x4F, RETROK_RIGHT },
{ 0x52, RETROK_UP },
{ 0x51, RETROK_DOWN },
{ 0x28, RETROK_RETURN },
{ 0x2B, RETROK_TAB },
{ 0x49, RETROK_INSERT },
{ 0x4C, RETROK_DELETE },
{ 0xE5, RETROK_RSHIFT },
{ 0xE1, RETROK_LSHIFT },
{ 0xE0, RETROK_LCTRL },
{ 0x4D, RETROK_END },
{ 0x4A, RETROK_HOME },
{ 0x4E, RETROK_PAGEDOWN },
{ 0x4B, RETROK_PAGEUP },
{ 0xE2, RETROK_LALT },
{ 0x2C, RETROK_SPACE },
{ 0x29, RETROK_ESCAPE },
{ 0x2A, RETROK_BACKSPACE },
{ 0x58, RETROK_KP_ENTER },
{ 0x57, RETROK_KP_PLUS },
{ 0x56, RETROK_KP_MINUS },
{ 0x55, RETROK_KP_MULTIPLY },
{ 0x54, RETROK_KP_DIVIDE },
{ 0x35, RETROK_BACKQUOTE },
{ 0x48, RETROK_PAUSE },
{ 0x62, RETROK_KP0 },
{ 0x59, RETROK_KP1 },
{ 0x5A, RETROK_KP2 },
{ 0x5B, RETROK_KP3 },
{ 0x5C, RETROK_KP4 },
{ 0x5D, RETROK_KP5 },
{ 0x5E, RETROK_KP6 },
{ 0x5F, RETROK_KP7 },
{ 0x60, RETROK_KP8 },
{ 0x61, RETROK_KP9 },
{ 0x27, RETROK_0 },
{ 0x1E, RETROK_1 },
{ 0x1F, RETROK_2 },
{ 0x20, RETROK_3 },
{ 0x21, RETROK_4 },
{ 0x22, RETROK_5 },
{ 0x23, RETROK_6 },
{ 0x24, RETROK_7 },
{ 0x25, RETROK_8 },
{ 0x26, RETROK_9 },
{ 0x3A, RETROK_F1 },
{ 0x3B, RETROK_F2 },
{ 0x3C, RETROK_F3 },
{ 0x3D, RETROK_F4 },
{ 0x3E, RETROK_F5 },
{ 0x3F, RETROK_F6 },
{ 0x40, RETROK_F7 },
{ 0x41, RETROK_F8 },
{ 0x42, RETROK_F9 },
{ 0x43, RETROK_F10 },
{ 0x44, RETROK_F11 },
{ 0x45, RETROK_F12 },
{ 0x04, RETROK_a },
{ 0x05, RETROK_b },
{ 0x06, RETROK_c },
{ 0x07, RETROK_d },
{ 0x08, RETROK_e },
{ 0x09, RETROK_f },
{ 0x0A, RETROK_g },
{ 0x0B, RETROK_h },
{ 0x0C, RETROK_i },
{ 0x0D, RETROK_j },
{ 0x0E, RETROK_k },
{ 0x0F, RETROK_l },
{ 0x10, RETROK_m },
{ 0x11, RETROK_n },
{ 0x12, RETROK_o },
{ 0x13, RETROK_p },
{ 0x14, RETROK_q },
{ 0x15, RETROK_r },
{ 0x16, RETROK_s },
{ 0x17, RETROK_t },
{ 0x18, RETROK_u },
{ 0x19, RETROK_v },
{ 0x1A, RETROK_w },
{ 0x1B, RETROK_x },
{ 0x1C, RETROK_y },
{ 0x1D, RETROK_z },
{ 0, RETROK_UNKNOWN }
};
#define MAX_TOUCH 16
#define MAX_KEYS 256
struct
{
@ -31,12 +214,38 @@ struct
int16_t full_x, full_y;
} ios_touches[MAX_TOUCH];
bool ios_keys[256];
bool ios_keys[MAX_KEYS];
uint32_t ios_current_touch_count = 0;
static bool l_ios_is_key_pressed(enum retro_key key)
{
if ((int)key >= 0 && key < RETROK_LAST)
{
int hidkey = input_translate_rk_to_keysym(key);
return (hidkey < MAX_KEYS) ? ios_keys[hidkey] : false;
}
return false;
}
static int16_t l_ios_joypad_device_state(const struct retro_keybind **binds_,
unsigned port_num, unsigned id)
{
const struct retro_keybind *binds = binds_[port_num];
if (id < RARCH_BIND_LIST_END)
{
const struct retro_keybind *bind = &binds[id];
return bind->valid && l_ios_is_key_pressed(bind->key);
}
else
return 0;
}
static void *ios_input_init(void)
{
input_init_keyboard_lut(rarch_key_map_hidusage);
memset(ios_touches, 0, sizeof(ios_touches));
memset(ios_keys, 0, sizeof(ios_keys));
return (void*)-1;
@ -57,25 +266,13 @@ static int16_t ios_input_state(void *data, const struct retro_keybind **binds, u
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (port != 0) return 0;
switch (id)
{
case RETRO_DEVICE_ID_JOYPAD_UP: return ios_keys[82];
case RETRO_DEVICE_ID_JOYPAD_DOWN: return ios_keys[81];
case RETRO_DEVICE_ID_JOYPAD_LEFT: return ios_keys[80];
case RETRO_DEVICE_ID_JOYPAD_RIGHT: return ios_keys[79];
case RETRO_DEVICE_ID_JOYPAD_B: return ios_keys[0x1D];
case RETRO_DEVICE_ID_JOYPAD_A: return ios_keys[0x1B];
case RETRO_DEVICE_ID_JOYPAD_Y: return ios_keys[0x04];
case RETRO_DEVICE_ID_JOYPAD_X: return ios_keys[0x1D];
case RETRO_DEVICE_ID_JOYPAD_START: return ios_keys[0x1A];
case RETRO_DEVICE_ID_JOYPAD_SELECT: return ios_keys[0x14];
case RETRO_DEVICE_ID_JOYPAD_L: return ios_keys[0x07];
case RETRO_DEVICE_ID_JOYPAD_R: return ios_keys[0x06];
default: return 0;
}
return l_ios_joypad_device_state(binds, port, id);
case RETRO_DEVICE_ANALOG:
return 0;
case RETRO_DEVICE_MOUSE:
return 0;
case RETRO_DEVICE_POINTER:
return 0;
case RARCH_DEVICE_POINTER_SCREEN:
switch (id)
{
@ -88,6 +285,11 @@ static int16_t ios_input_state(void *data, const struct retro_keybind **binds, u
default:
return 0;
}
case RETRO_DEVICE_KEYBOARD:
return 0;
case RETRO_DEVICE_LIGHTGUN:
return 0;
default:
return 0;
}
@ -95,18 +297,12 @@ static int16_t ios_input_state(void *data, const struct retro_keybind **binds, u
static bool ios_input_key_pressed(void *data, int key)
{
switch (key)
const struct retro_keybind *binds = g_settings.input.binds[0];
if (key >= 0 && key < RARCH_BIND_LIST_END)
{
case RARCH_FAST_FORWARD_KEY: return ios_keys[0x2C];
case RARCH_FAST_FORWARD_HOLD_KEY: return ios_keys[0x0F];
case RARCH_LOAD_STATE_KEY: return ios_keys[0x03D];
case RARCH_SAVE_STATE_KEY: return ios_keys[0x03B];
case RARCH_STATE_SLOT_PLUS: return ios_keys[0x40];
case RARCH_STATE_SLOT_MINUS: return ios_keys[0x3F];
case RARCH_REWIND: return ios_keys[0x15];
case RARCH_PAUSE_TOGGLE: return ios_keys[0x13];
case RARCH_FRAMEADVANCE: return ios_keys[0x0E];
case RARCH_RESET: return ios_keys[0x0B];
const struct retro_keybind *bind = &binds[key];
return l_ios_is_key_pressed(bind->key);
}
return false;

View File

@ -41,6 +41,18 @@ static NSMutableDictionary* boolean_setting(config_file_t* config, NSString* nam
nil];
}
static NSMutableDictionary* button_setting(config_file_t* config, NSString* name, NSString* label, NSString* defaultValue)
{
NSString* value = get_value_from_config(config, name, defaultValue);
return [[NSMutableDictionary alloc] initWithObjectsAndKeys:
@"C", @"TYPE",
name, @"NAME",
label, @"LABEL",
value, @"VALUE",
nil];
}
static NSMutableDictionary* enumeration_setting(config_file_t* config, NSString* name, NSString* label, NSString* defaultValue, NSArray* values)
{
NSString* value = get_value_from_config(config, name, defaultValue);
@ -72,6 +84,47 @@ static NSMutableDictionary* subpath_setting(config_file_t* config, NSString* nam
nil];
}
@interface button_getter : NSObject<UIAlertViewDelegate>
@end
@implementation button_getter
{
button_getter* me;
NSMutableDictionary* value;
UIAlertView* alert;
}
- (id)initWithSetting:(NSMutableDictionary*)setting
{
value = setting;
alert = [[UIAlertView alloc] initWithTitle:@"RetroArch"
message:[value objectForKey:@"LABEL"]
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert show];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyReleased:) name: GSEventKeyUpNotification object: nil];
me = self;
return self;
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
me = nil;
}
- (void)keyReleased:(NSNotification*) notification
{
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
@end
@interface enumeration_list : UITableViewController
@end
@ -160,6 +213,21 @@ static NSMutableDictionary* subpath_setting(config_file_t* config, NSString* nam
subpath_setting(config, @"input_overlay", @"Input Overlay", @"", overlay_path, @"cfg"),
nil],
[NSArray arrayWithObjects:@"System Keys",
button_setting(config, @"input_save_state", @"Save State", @"f2"),
button_setting(config, @"input_load_state", @"Load State", @"f4"),
button_setting(config, @"input_state_slot_increase", @"Next State Slot", @"f7"),
button_setting(config, @"input_state_slot_decrease", @"Previous State Slot", @"f6"),
button_setting(config, @"input_toggle_fast_forward", @"Toggle Fast Forward", @"space"),
button_setting(config, @"input_hold_fast_forward", @"Hold Fast Forward", @"l"),
button_setting(config, @"input_rewind", @"Rewind", @"r"),
button_setting(config, @"input_slowmotion", @"Slow Motion", @"e"),
button_setting(config, @"input_pause_toogle", @"Pause", @"p"),
button_setting(config, @"input_frame_advance", @"Advance Frame", @"k"),
button_setting(config, @"input_reset", @"Reset", @"h"),
button_setting(config, @"input_exit_emulator", @"Close Game", @"escape"),
nil],
[NSArray arrayWithObjects:@"Save States",
boolean_setting(config, @"rewind_enable", @"Enable Rewinding", @"false"),
boolean_setting(config, @"block_sram_overwrite", @"Disable SRAM on Load", @"false"),
@ -219,6 +287,10 @@ static NSMutableDictionary* subpath_setting(config_file_t* config, NSString* nam
pushViewController:[[enumeration_list alloc] initWithSetting:setting fromTable:(UITableView*)self.view]
animated:YES];
}
else if([type isEqualToString:@"C"])
{
[[button_getter alloc] initWithSetting:setting];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@ -269,7 +341,7 @@ static NSMutableDictionary* subpath_setting(config_file_t* config, NSString* nam
objc_setAssociatedObject(swt, SETTINGID, setting, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
else if ([type isEqualToString:@"E"] || [type isEqualToString:@"F"])
else if ([type isEqualToString:@"E"] || [type isEqualToString:@"F"] || [type isEqualToString:@"C"])
{
cell = [self.tableView dequeueReusableCellWithIdentifier:@"enumeration"];