Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone/iPad app using keyboard shortcuts?

With the availability of keyboards for iPads and iPhones, it makes sense to add keyboard shortcuts to apps now.

Is it possible to do this in an app? What are the relevant APIs?

like image 619
imno Avatar asked Jul 28 '10 00:07

imno


1 Answers

While this question is fairly old, Apple has added support for keyboard specific shortcuts in iOS 7. Check out the UIKeyCommand class in the UIKit Framework for special support for hardware keyboard shortcuts. The high level steps for us are:

  1. Use the static keyCommandWithInput:modifierFlags:action: method on the UIKeyCommand class to create an instance of the UIKeyCommand for the specified keys with modifiers. Note that any keyboard shortcuts handled by the system (like Command-C for copy) will not work. You will also pass an action selector that will be called when the keyboard shortcut is used
  2. Associate this newly created UIKeyCommand with your responder object(s) by returning them from the responder object's keyCommand property.
  3. When the keys are pressed, your selector will be called.
like image 126
Michael McGuire Avatar answered Oct 08 '22 18:10

Michael McGuire