(iOS) Add ‘Small Keyboard’ input mode which repurposes certain keys while right shift is held.

Notably the tilde, number keys, minus and equals are changed to send Escape and F1-F12.  This is useful on iPad specific keyboards where these keys are otherwise unavailable.
This commit is contained in:
meancoot 2014-01-15 22:14:58 -05:00
parent 682bd74a28
commit b530dce2d2
3 changed files with 71 additions and 4 deletions

View File

@ -49,8 +49,63 @@ const unsigned char MAC_NATIVE_TO_HID[128] = {
// Main thread interface
static bool icade_enabled;
static bool small_keyboard_enabled;
static bool small_keyboard_active;
static uint32_t icade_buttons;
static bool handle_small_keyboard(unsigned* code, bool down)
{
static const struct { uint8_t orig; uint8_t mod; } mapping_def[] =
{
{ KEY_Grave, KEY_Escape }, { KEY_1, KEY_F1 },
{ KEY_2, KEY_F2 }, { KEY_3, KEY_F3 },
{ KEY_4, KEY_F4 }, { KEY_5, KEY_F5 },
{ KEY_6, KEY_F6 }, { KEY_7, KEY_F7 },
{ KEY_8, KEY_F8 }, { KEY_9, KEY_F9 },
{ KEY_0, KEY_F10 }, { KEY_Minus, KEY_F11 },
{ KEY_Equals, KEY_F12 }, { KEY_Up, KEY_PageUp },
{ KEY_Down, KEY_PageDown }, { KEY_Left, KEY_Home },
{ KEY_Right, KEY_End }, { KEY_Q, KP_7 },
{ KEY_W, KP_8 }, { KEY_E, KP_9 },
{ KEY_A, KP_4 }, { KEY_S, KP_5 },
{ KEY_D, KP_6 }, { KEY_Z, KP_1 },
{ KEY_X, KP_2 }, { KEY_C, KP_3 },
{ 0 }
};
static uint8_t mapping[128];
static bool map_initialized;
if (!map_initialized)
{
for (int i = 0; mapping_def[i].orig; i ++)
mapping[mapping_def[i].orig] = mapping_def[i].mod;
map_initialized = true;
}
if (*code == KEY_RightShift)
{
small_keyboard_active = down;
*code = 0;
return true;
}
unsigned translated_code = (*code < 128) ? mapping[*code] : 0;
// Allow old keys to be released
if (!down && g_current_input_data.keys[*code])
return false;
if ((!down && g_current_input_data.keys[translated_code]) ||
small_keyboard_active)
{
*code = translated_code;
return true;
}
return false;
}
static void handle_icade_event(unsigned keycode)
{
static const struct
@ -86,6 +141,11 @@ void apple_input_enable_icade(bool on)
icade_buttons = 0;
}
void apple_input_enable_small_keyboard(bool on)
{
small_keyboard_enabled = on;
}
uint32_t apple_input_get_icade_buttons(void)
{
return icade_enabled ? icade_buttons : 0;
@ -106,9 +166,14 @@ void apple_input_keyboard_event(bool down, unsigned code, uint32_t character, ui
return;
}
if (code < MAX_KEYS)
g_current_input_data.keys[code] = down;
if (small_keyboard_enabled && handle_small_keyboard(&code, down))
character = 0;
if (code == 0 || code >= MAX_KEYS)
return;
g_current_input_data.keys[code] = down;
enum
{
NSAlphaShiftKeyMask = 1 << 16,

View File

@ -71,6 +71,7 @@ extern apple_input_data_t g_polled_input_data;
// Main thread only
void apple_input_enable_icade(bool on);
void apple_input_enable_small_keyboard(bool on);
uint32_t apple_input_get_icade_buttons(void);
void apple_input_reset_icade_buttons(void);
void apple_input_keyboard_event(bool down, unsigned code, uint32_t character, uint32_t mod);

View File

@ -44,6 +44,7 @@ int get_ios_version_major(void)
void ios_set_bluetooth_mode(NSString* mode)
{
apple_input_enable_small_keyboard([mode isEqualToString:@"small_keyboard"]);
apple_input_enable_icade([mode isEqualToString:@"icade"]);
btstack_set_poweron([mode isEqualToString:@"btstack"]);
}
@ -71,9 +72,9 @@ const void* apple_get_frontend_settings(void)
// Set ios_btmode options based on runtime environment
if (btstack_try_load())
settings[4].values = "none|icade|keyboard|btstack";
settings[4].values = "icade|keyboard|small_keyboard|btstack";
else
settings[4].values = "none|icade|keyboard";
settings[4].values = "icade|keyboard|small_keyboard";
settings[5] = setting_data_string_setting(ST_STRING, "ios_orientations", "Screen Orientations", apple_frontend_settings.orientations,
sizeof(apple_frontend_settings.orientations), "both");