title: iOS Make Custom Keyboard Generate Standard Key Strokes For UITextField
body: <p>OK I have looked and looked and I think I am missing something about custom keyboards and inserting text into a <code>UITextField</code>.  Like many people I am creating a <code>UIView</code> custom keyboard with my own set of key caps on custom <code>UIButtons</code>.  I then assign this view to the UITextField's <code>inputView</code> and then my keyboard pops up when that text field becomes the first responder.  Internal to the keyboard I capture button actions and translate them to what would be keystrokes.</p>
  
  <p>But from here I am puzzled about how to best send my keystrokes to the text field.  I have seen plenty of examples like <a href="https://stackoverflow.com/questions/7140770/ios-custom-keyboard-updating-text-field-in-parent-view">iOS Custom Keyboard Updating Text Field In Parent View</a> and <a href="https://stackoverflow.com/questions/3224757/return-inputs-to-uitextfield-with-custom-inputview">Return Inputs To UITextfield With Custom Inputview</a> and <a href="https://stackoverflow.com/questions/4788937/how-to-push-key-value-into-uitextview-from-custom-keyboard-in-ios">How To Push Key Value Into UITextView From Custom Keyboard In iOS</a> where the solution seems to be to embed a pointer to the target <code>UITextField</code> inside the custom view.  </p>
  
  <p>This does not seem right to me, as for multiple <code>UITextFields</code> either I have to have to manually change references on a single custom keyboard  whenever a new text field becomes the first responder, or I have to carry around a matching  custom keyboard for each text field I want to support.</p>
  
  <p>It seems to me that a keyboard should just translate touches into tokens and send those tokens up the line to be interpreted by whoever receives them (first responder?).  <a href="http://www.raywenderlich.com/1063/ipad-for-iphone-developers-101-custom-input-view-tutorial" rel="nofollow noreferrer">iPad For iPhone Developers 101 Custom Input View Tutorial</a> seems to do this, but creates a custom protocol to do so.  I imagine (actually a SWAG - Scientific Wild Arsed Guess) that the standard iOS keyboards operate like that, but use a specific protocol to pass along the keystrokes.  So what I want to be able to do is to manually generate the same chain of events/messages that the standard keyboard does.</p>
  
  <p>So how can I do this?  Or can I even do this with public APIs?  Or is the operation of the standard keyboards bound too tightly to the UITextField?</p>