Forum Archive

Getting What Key is Pressed on Keyboard

procryon

Hey guys I have a simple question. I saw a post on the forum here that was related to this but unfortunately, the only answer on that post did not clarify enough for me. So what I need to ask is this:

Say I ask for a user’s input in a text field, how do I make it so that instead of having to press a button in order for the user’s input to be processed, the user can simply hit “return” on the keyboard.

JonB

For TextField, which contains a single line, pressing Enter automatically calls the action method, so the following also works

def a(sender):
  #called when done entering text
  print(sender.text ')
t=ui.TextField(a)
t.action=a
t.present('popover')

For TextView, you would instead use one of the delegate methods textview_did_change, or textview_should_change.

Phuket2

@procryon , if you look at one of my code examples in this thread you see the delegate being used as @JonB pointed out.
You can see the TextFields Delegate Documentation here