1

I want to programmatically detect whether an external keyboard connected or virtual keyboard is visible on given view. How can I do it?

I could do it using Keyboard notifications but I need a different way to do it. Is there any other way to do it?

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
Suravi
  • 301
  • 1
  • 7
  • 21

1 Answers1

0

Maybe this helps...

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 Recieve :

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

}

This will be called just when inside keyboard will be showned and no external keyboard is attached ! If external keyboard is attached WillShow Notification won't be called .

Source: How to detect external keyboard connectification in objective-c?


Another way could be:

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.

Source: How can I detect if an external keyboard is present on an iPad?

Community
  • 1
  • 1
nirvana002
  • 75
  • 1
  • 7
  • problem is here i use uiwebviw with editable div.so UIKeyboardWillShowNotification also calling with external key board? – Suravi Dec 18 '13 at 10:19