Programming for the iPad keyboard - a few questions
I think I've done my homework on this, but haven't found what I'm looking for.
I'm developing an iPad app and I'd like to be able to:
Watch for keypress events (if there are such things) and respond to them by:
- altering what was entered and have the altered resu开发者_运维技巧lts appear in the UITextField (instead of what the user entered). This could be a macro, for example.
- in some cases, I'd like to programmatically hit the shift button, so the next work the user enters begins with a capital letter.
I have seen in similar questions references to the UITextInput protocol, but I wasnt sure what I found there would be applicable here.
Any thoughts?
Thanks.
Example for UITextField
Connect the UITextField delegate to the app delegate, and add the following code:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if([string isEqual:@"b"]) {
textField.text = [textField.text stringByReplacingCharactersInRange:range withString:@"!"];
return NO;
} else {
return YES;
}
}
Every time the user presses the 'b' key it shows an exclamation mark.
All other keys work as usual.
This way you can also change the case.
For example, when the user hits 'b', update the field with 'B'.
It's currently not possible to press the shift key by code.
精彩评论