I am working on an app that uses voice commands to maneuver through text fields. What I need to do is translate the voice command into a touch event on the keyboard. Specifically I need to access the tab key and the return key. The user will not be using the keyboard in this app. I am having a difficult time finding a way to get this done. I know how to convert the voice commands into something that I can use, but I still need to apply that to the keyboard commands. I have researched this extensively and I get what I think are bits and pieces of what I really need, but nothing is connecting the dots for me.
Share
You don’t need the keyboard to navigate text fields. You just need to modify the first responder. There unfortunately isn’t an easy way to get the current first responder, but you can search for it.
Once you have the first responder, you can move to the next field like this:
If you are trying to do this in a very general way, you should first call
canBecomeFirstResponderand handle situations where there there are no available first responders and other corner cases, but this generally isn’t needed for very simple interfaces.If you want to manage “enter” in order to end editing and dismiss the keyboard, you can call
endEditing:on the superview.You can modify text without the keyboard by replacing the
textproperty.