Detect A RETURN keypress to run function.
Hi All, I hope you are all having a great holiday! If you like me you having fun with your iPad and Pythonista!
I have been looking everywhere and can not find a way to detect a RETURN keypress to run a function. Do not know if that is OS specific or not...
Where exactly do you want to detect a Return key press? If you want to read text input from the user, you can use Python's
input(Python 3) or
raw_input(Python 2) function. This is a standard Python function, so it works on all systems, including Pythonista.
Hi dgelessue, thanks!
I already get input from a user via a ui TextField and pass to a function when a Button is pressed, which works fine. But, just in case a user wanted to use the keyboard instead of the button, I wanted to have an option to press a Return Key..
ui.TextFields have an
actionattribute, which you can set to a function, which is called when you press Return in the text field (either on the onscreen keyboard or on an external Bluetooth keyboard). By default I think this doesn't unfocus the text field, so you might want to call
end_editing()on the text field, so the onscreen keyboard goes away when pressing Return.
Thanks dgelessus! That works great!