diff --git a/apple/OSX/platform.m b/apple/OSX/platform.m index 384ccca7a7..406bca1350 100644 --- a/apple/OSX/platform.m +++ b/apple/OSX/platform.m @@ -44,11 +44,10 @@ static void* const associated_core_key = (void*)&associated_core_key; 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]); + 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]); + apple_input_keyboard_event(event_type == NSKeyDown, 0, [ch characterAtIndex:i], [event modifierFlags]); } } else if (event_type == NSFlagsChanged) diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index 684ef2cda9..2c9750f695 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -135,6 +135,8 @@ static void handle_touch_event(NSArray* touches) @interface UIEvent(iOS7Keyboard) @property(readonly, nonatomic) long long _keyCode; @property(readonly, nonatomic) _Bool _isKeyDown; +@property(retain, nonatomic) NSString *_privateInput; +@property(nonatomic) long long _modifierFlags; - (struct __IOHIDEvent { }*)_hidEvent; @end @@ -150,9 +152,29 @@ static void handle_touch_event(NSArray* touches) // Keyboard handler for iOS 7 - (id)_keyCommandForEvent:(UIEvent*)event { - // If the _hidEvent is null, [event _keyCode] will crash. + // This gets called twice with the same timestamp for each keypress, that's fine for polling + // but is bad for business with events. + static double last_time_stamp; + + if (last_time_stamp == [event timestamp]) + return [super _keyCommandForEvent:event]; + last_time_stamp = [event timestamp]; + + // If the _hidEvent is null, [event _keyCode] will crash. (This happens with the on screen keyboard.) if ([event _hidEvent]) - apple_input_keyboard_event([event _isKeyDown], [event _keyCode], 0, 0); + { + NSString* ch = [event _privateInput]; + + if (!ch || [ch length] == 0) + apple_input_keyboard_event([event _isKeyDown], [event _keyCode], 0, [event _modifierFlags]); + else + { + apple_input_keyboard_event([event _isKeyDown], [event _keyCode], [ch characterAtIndex:0], [event _modifierFlags]); + + for (unsigned i = 1; i != [ch length]; i ++) + apple_input_keyboard_event([event _isKeyDown], 0, [ch characterAtIndex:i], [event _modifierFlags]); + } + } return [super _keyCommandForEvent:event]; }