iOS : How to detect any key pressed when use a BT keyboard

218 Views Asked by At

I have to implement a manufacturer keyboard test app of iOS on iPad.

I am surveying on this topic right now.

According to this article

[_myUITextField becomeFirstResponder];
[_myUITextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventAllEvents];
}

-(IBAction)textFieldDidChange:(id)sender{
    UITextField *_field = (UITextField *)sender;
    NSLog(@"%@",[_field text]);
}

With these code I can detect the letter(like 1,2,3,a,b,c...) I pressed in my app, but not all key pressed (like fn, ctl, cmd ...etc?)

Anyone know how to achieve this...thanks^^

1

There are 1 best solutions below

1
Snowmanzzz On

Try Notification center instead.

 NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

UITextField :

[notificationCenter addObserver:self
                   selector:@selector (textFieldText:)
                       name:UITextFieldTextDidChangeNotification
                     object:yourtextfield];