Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
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...
?
Thanks!
-
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) orraw_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.TextField
s have anaction
attribute, 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 callend_editing()
on the text field, so the onscreen keyboard goes away when pressing Return. -
Thanks dgelessus! That works great!