There is a 100% supported way to handle keyboard shortcuts on a Bluetooth keyboard in iOS 7 using the new UIKeyCommand class and UIResponder chain. I made a blog about it , but here's the gist:
Somewhere in the responder chain, add the keyCommands method, which returns an array of UIKeyCommand objects:
- (NSArray *)keyCommands { UIKeyCommand *commandF = [UIKeyCommand keyCommandWithInput:@"f" modifierFlags:UIKeyModifierCommand action:@selector(handleCommandF:)]; return @[commandF]; }
Then, when βF is pressed (as text input), the responder chain will look for this handleCommandF method. If there are several definitions, then it will use the narrowest area (for example, the view itself takes precedence over the ViewController).
Note that this will only work if the input (e.g. UITextField or UITextView ) is the first responder. If you want to use βglobalβ shortcuts in your application, you can do a trick in which you hide the UITextField off-screen and focus on that.
swilliams
source share