I\'m trying to figure out how to detect that the Escape (and other key combinations like Ctrl and alt) have been pressed on a bluetooth keyboard attached to an iOS device.
AFAIK this is not possible using public API.
I've done a bit of searching and the esc key is not recognized.
The only thing that I didn't do is to try iSSH
(it costs 9€ :-), but if you read the description on the AppStore it seems clear that ESC key on a hardware (bluetooth) keyboard doesn't work:
Exhaustive key configuration support. Has arrow keys (by pop-up or by toolbar). ctrl, alt, esc, tab, shift, Fn keys (1-10), ` key, PgUp, PgDown and for those keys not listed provides multiple means to add them.
Bluetooth keyboard support for arrow keys, function keys and a remapping of the ctrl key through option key mapping in either X11/VNC
server or terminal. When enabled, an Option+key press maps to equivalent Ctrl+key press.
As you can see, in the second line the ESC key is not mentioned. Moreover, I've found this (old) post.
EDIT:
As your last updates, I've found a way to "hide" the _gsEvent
inside the binary. I don't know if Apple static analyser can find it, however.
The trick is simple...create the _gsEvent
selector (and other private selectors) at runtime!
-(void)sendEvent:(UIEvent *)event
{
SEL aSelector = NSSelectorFromString([self theSelector]);
if ([event respondsToSelector:aSelector]) {
NSLog(@"Event: %@", event.description);
}
[super sendEvent:event];
}
-(NSString *)theSelector
{
// compose the keyword as you prefer
NSString *sel = [NSString stringWithFormat:@"%@g%@%@ent", @"_", @"s", @"Ev"];
return sel;
}
I've tried to search inside the binary and I don't find the _gsEvent
keyword, obviously because it's created only at runtime.
Hope this helps.
You can do this now in iOS 7. For example, to implement the escape key, override UITextView and place the following methods in your class:
- (NSArray *) keyCommands {
UIKeyCommand *esc = [UIKeyCommand keyCommandWithInput: UIKeyInputEscape modifierFlags: 0 action: @selector(esc:)];
return [[NSArray alloc] initWithObjects: esc, nil];
}
- (void) esc: (UIKeyCommand *) keyCommand {
// Your custom code goes here.
}
You don't need to check to be sure you are on iOS 7, since earlier versions of the OS won't call the keyCommands method.
There are no public APIs for what you intend to accomplish, so this may lead to a rejection.
If you are willing to risk it, you can try this. Wich basically intercepts all events sent to your App by overwriting sendEvent:
in your UIApplication
.