Search code examples
ipadios5uikeyboarduikeyinput

How to know which key is pressed on UIKeyboard in ios?


I am implementing a iPad application. In my application I need to know which key is pressed in the keyborad. Can you guys please help me is there any way to find it?

Thank you, Sekhar.


Solution

  • This is a vague question, but if you simply want to know what key has been tapped you need to implement a delegate for input control that called the keyboard. For example if you are using a UITextView, then implement the UITextViewDelegate, wire up the control's delegate property to you class, and then implement the textView:shouldChangeTextInRange:replacementText:. When UITextView recognizes a change then it will call this method. You can then watch for the characters in the "replacementText" argument.

    With UITextField use the UITextFieldDelegate and implement the textField:shouldChangeCharactersInRange:replacementString: method.

    You can do other things with UITextField like change the Return button to a Done button in Interface Builder. The implement the textFieldShouldReturn: method. If it's called then run the resignFirstResponder on the object passed to the method.

    Hope this helps.