views:

367

answers:

1

Is there a way to detect if an external (bluetooth or usb) keyboard is connected to the iPad?

Thanks!

+2  A: 

An indirect and SDK-safe way is to make a text field a first responder. If the external keyboard is present, the UIKeyboardWillShowNotification local notification shall not be posted.

You can listen to the "GSEventHardwareKeyboardAttached" (kGSEventHardwareKeyboardAvailabilityChangedNotification) Darwin notification, but this is a private API, so it's possible your app will get rejected if you use this. To check if the external hardware is present, use the private GSEventIsHardwareKeyboardAttached() function.

UIKit listens to this and sets the UIKeyboardImpl.isInHardwareKeyboardMode property accordingly, but again this is private API.

KennyTM
Is there no way of doing this with public calls? Having my app get rejected kind of defeats the purpose of writing it in the first place =)
carloe
@carloe: Why are you needing it in the first place? :)
KennyTM
@KennyTM I could very well be going at this the wrong way =) I have a UIView that needs to be positioned differently depending on whether or not the iPad's virtual keyboard is displayed on the screen...
carloe
@carloe: You can listen to the UIKeyboard[Will|Did][Show|Hide]Notification notifications and adjust the view's position accordingly, just like everyone did on the iPhone (when the keyboard appears and disappears)...
KennyTM
@KennyTM that worked. Thank you!
carloe