omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.

    Pythonista
    2
    5
    4546
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • starrshaw
      starrshaw last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • starrshaw
          starrshaw last edited by

          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..

          1 Reply Last reply Reply Quote 0
          • dgelessus
            dgelessus last edited by

            ui.TextFields have an action 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 call end_editing() on the text field, so the onscreen keyboard goes away when pressing Return.

            1 Reply Last reply Reply Quote 0
            • starrshaw
              starrshaw last edited by

              Thanks dgelessus! That works great!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors