How to detect an external keyboard in objective-c?

My application should know that an external keyboard is connected or not. How could I find out? No Private API, please. :)

+5
source share
2 answers

If this is due to iOS, I'm not sure why you want to detect it, since the hardware keyboard acts exactly like the software keyboard (with the exception of a few additional shortcuts for sound, brightness, etc. that your application should not use anyway).

If you view the space on the screen, then the software keyboard will still send notifications when it is displayed or when it is hidden so that you can answer them. For example, let's say you have a soft keyboard, and then you plug in an external keyboard. The soft keyboard will hide and publish the UIKeyboardWillHideNotification. Therefore, you can answer that.

0
source

First Register Notification:

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

Then:

-(void)keyboardWillHide:(NSNotification *)_notification {
   NSLog(@"%@",[_notification infoDict]);
}
-(void)keyboardWillShow:(NSNotification *)_notification {
   NSLog(@"%@",[_notification infoDict]);
}

This will only be called when the internal keyboard is displayed and the external keyboard is not connected! If an external keyboard is connected, the WillShow Notation will not be called.

-1
source

All Articles