mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 00:32:49 +00:00
(Apple) Add keyboard event+character data support. (No char data for iOS)
This commit is contained in:
parent
83a416308c
commit
5747106e64
@ -37,7 +37,20 @@ static void* const associated_core_key = (void*)&associated_core_key;
|
||||
NSEventType event_type = [event type];
|
||||
|
||||
if (event_type == NSKeyDown || event_type == NSKeyUp)
|
||||
apple_input_handle_key_event([event keyCode], event_type == GSEVENT_TYPE_KEYDOWN);
|
||||
{
|
||||
NSString* ch = [event characters];
|
||||
|
||||
if (!ch || [ch length] == 0)
|
||||
apple_input_keyboard_event(event_type == NSKeyDown, [event keyCode], 0, 0);
|
||||
else
|
||||
{
|
||||
if ([ch length] >= 1)
|
||||
apple_input_keyboard_event(event_type == NSKeyDown, [event keyCode], [ch characterAtIndex:0], [event modifierFlags]);
|
||||
|
||||
for (unsigned i = 1; i != [ch length]; i ++)
|
||||
apple_input_keyboard_event(event_type == NSKeyDown, 0, [ch characterAtIndex:0], [event modifierFlags]);
|
||||
}
|
||||
}
|
||||
else if (event_type == NSFlagsChanged)
|
||||
{
|
||||
static uint32_t old_flags = 0;
|
||||
@ -45,7 +58,7 @@ static void* const associated_core_key = (void*)&associated_core_key;
|
||||
bool down = (new_flags & old_flags) == old_flags;
|
||||
old_flags = new_flags;
|
||||
|
||||
apple_input_handle_key_event([event keyCode], down);
|
||||
apple_input_keyboard_event(down, [event keyCode], 0, [event modifierFlags]);
|
||||
}
|
||||
else if (event_type == NSMouseMoved || event_type == NSLeftMouseDragged ||
|
||||
event_type == NSRightMouseDragged || event_type == NSOtherMouseDragged)
|
||||
|
@ -96,14 +96,41 @@ void apple_input_reset_icade_buttons(void)
|
||||
icade_buttons = 0;
|
||||
}
|
||||
|
||||
void apple_input_handle_key_event(unsigned keycode, bool down)
|
||||
void apple_input_keyboard_event(bool down, unsigned code, uint32_t character, uint32_t mod)
|
||||
{
|
||||
keycode = HIDKEY(keycode);
|
||||
code = HIDKEY(code);
|
||||
|
||||
if (icade_enabled)
|
||||
handle_icade_event(keycode);
|
||||
else if (keycode < MAX_KEYS)
|
||||
g_current_input_data.keys[keycode] = down;
|
||||
{
|
||||
handle_icade_event(code);
|
||||
return;
|
||||
}
|
||||
|
||||
if (code < MAX_KEYS)
|
||||
g_current_input_data.keys[code] = down;
|
||||
|
||||
enum
|
||||
{
|
||||
NSAlphaShiftKeyMask = 1 << 16,
|
||||
NSShiftKeyMask = 1 << 17,
|
||||
NSControlKeyMask = 1 << 18,
|
||||
NSAlternateKeyMask = 1 << 19,
|
||||
NSCommandKeyMask = 1 << 20,
|
||||
NSNumericPadKeyMask = 1 << 21,
|
||||
NSHelpKeyMask = 1 << 22,
|
||||
NSFunctionKeyMask = 1 << 23,
|
||||
NSDeviceIndependentModifierFlagsMask = 0xffff0000U
|
||||
};
|
||||
|
||||
enum retro_mod mods = RETROKMOD_NONE;
|
||||
mods |= (mod & NSAlphaShiftKeyMask) ? RETROKMOD_CAPSLOCK : 0;
|
||||
mods |= (mod & NSShiftKeyMask) ? RETROKMOD_SHIFT : 0;
|
||||
mods |= (mod & NSControlKeyMask) ? RETROKMOD_CTRL : 0;
|
||||
mods |= (mod & NSAlternateKeyMask) ? RETROKMOD_ALT : 0;
|
||||
mods |= (mod & NSCommandKeyMask) ? RETROKMOD_META : 0;
|
||||
mods |= (mod & NSNumericPadKeyMask) ? RETROKMOD_NUMLOCK : 0;
|
||||
|
||||
input_keyboard_event(down, input_translate_keysym_to_rk(code), character, mods);
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +73,7 @@ extern apple_input_data_t g_polled_input_data;
|
||||
void apple_input_enable_icade(bool on);
|
||||
uint32_t apple_input_get_icade_buttons(void);
|
||||
void apple_input_reset_icade_buttons(void);
|
||||
void apple_input_handle_key_event(unsigned keycode, bool down);
|
||||
void apple_input_keyboard_event(bool down, unsigned code, uint32_t character, uint32_t mod);
|
||||
|
||||
extern int32_t apple_input_find_any_key(void);
|
||||
extern int32_t apple_input_find_any_button(uint32_t port);
|
||||
|
@ -152,7 +152,7 @@ static void handle_touch_event(NSArray* touches)
|
||||
{
|
||||
// If the _hidEvent is null, [event _keyCode] will crash.
|
||||
if ([event _hidEvent])
|
||||
apple_input_handle_key_event([event _keyCode], [event _isKeyDown]);
|
||||
apple_input_keyboard_event([event _isKeyDown], [event _keyCode], 0, 0);
|
||||
|
||||
return [super _keyCommandForEvent:event];
|
||||
}
|
||||
@ -171,7 +171,7 @@ static void handle_touch_event(NSArray* touches)
|
||||
int eventType = eventMem ? *(int*)&eventMem[8] : 0;
|
||||
|
||||
if (eventType == GSEVENT_TYPE_KEYDOWN || eventType == GSEVENT_TYPE_KEYUP)
|
||||
apple_input_handle_key_event(*(uint16_t*)&eventMem[0x3C], eventType == GSEVENT_TYPE_KEYDOWN);
|
||||
apple_input_keyboard_event(eventType == GSEVENT_TYPE_KEYDOWN, *(uint16_t*)&eventMem[0x3C], 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user