开发者

Programming for the iPad keyboard - a few questions

开发者 https://www.devze.com 2023-02-19 04:45 出处:网络
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:

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:

  1. 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.
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消