(iOS) Pass character data with physical keyboard events.

This commit is contained in:
meancoot 2014-01-12 20:24:50 -05:00
parent fd322bea8d
commit 8488afe89f
2 changed files with 26 additions and 5 deletions

View File

@ -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)

View File

@ -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];
}