Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Call function when Enter is pressed

edited September 2013 in Questions Posts: 5

Good day everyone!

I'd like to ask how to call a function when the Enter button is pressed on the keyboard. I have this highscore thing and the problem is when the user writes the username and pushes Enter, it goes to a new line. Is there a way to make it call a function (save the thing) or better yet change "return" to "go" and then call a function?

Thanks in advance.

Tagged:

Comments

  • edited September 2013 Posts: 1,595

    Here, add any additional functions after hideKeyboard()

    function keyboard(k)
        if k == "\n" then 
            hideKeyboard() 
            return 
        end
    end
    
  • dave1707dave1707 Mod
    Posts: 7,523

    @Luatee @gamebug The keywords RETURN and BACKSPACE can be used in the keyboard routine. See below.

    function keyboard(k)
        if k == RETURN then 
            hideKeyboard() 
            return 
        end
    end
    
  • edited September 2013 Posts: 1,595

    @Dave1707 I know but \n is shorter and relates to the string character, seems more understandable to me as I use it a lot in creating text boxes and stuff for multiline

  • Thank you very much guys!

Sign In or Register to comment.