In an iOS app, how do I determine if a user has pressed one of the arrow keys on his external keyboard?

I have several iOS apps that are linearly organized information that allows the user to move forward and backward through data using on-screen controls. I would like to allow users with a keyboard dock or a paired Bluetooth keyboard to use the arrow keys to move forward and backward. Since applications are full-screen, it is very important for users that there is no risk of displaying an on-screen keyboard as a side effect.

I cannot find an API that will allow me to do this in the Apple documentation; but I cannot be sure that I used the correct search terms.

What APIs exist that will allow me to achieve this?

Update: I raised this as an improvement on the Apple bug report site .

+6
ios bluetooth keyboard arrow-keys
source share
4 answers

I don’t know, I suspect the answer is "you cannot, not officially."

Since the user-friendly interface is a top priority for the iPad platform according to Apple, I think they are doing everything possible to discourage behavior that will depend on the available keyboard. Applications should behave the same and provide the same functionality with or without a hardware keyboard. Things like keyboard shortcuts or navigation that don't use screen elements are probably no-no for this reason: s.

But, as I said, this is just an assumption.

0
source share

You can easily determine which arrow keys are pressed by referring to UIKeyInput and UIKeyInputDelegate . The method you are looking for is positionFromPosition:inDirection:offset:

After calling this method (it is used by iOS to determine the selection range), it is called setSelectedText: Put the NSLog statements in positionFromPosition:inDirection:offset: to determine how it works (you are responsible for the plumbing).

Also see SimpleTextInput . This will provide you with a template for subclassing UITextInput .

+3
source share

Answer in How can I answer external keyboard arrow keys? - create a hidden text box and respond to selection changes - worked for me.

+3
source share

You can completely eliminate the keyboard by simply adding left / right swipe support or a drag gesture so that the user can essentially treat the application as a photo gallery. No on-screen controls are required - this is a device-based paradigm that is easy to explain on the app launch screen saver.

If an external keyboard is required to support other application data collection functions, users may encounter a gorilla hand problem ...

0
source share

All Articles