Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    GetKeyboardBuffer - How do I detect the enter key?

    Beginners
    3
    4
    296
    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.
    • RodrigoDavy
      RodrigoDavy last edited by

      I tried it like like this:

      k = getKeyboardBuffer()
      
      if(k == "\n") then
          print("Bingo")
      endif
      

      It doesn't work. I have no idea how to detect enter. If anybody could help, I'd be grateful :)

      1 Reply Last reply Reply Quote 2
      • RodrigoDavy
        RodrigoDavy last edited by RodrigoDavy

        I found a way to do it

        showKeyboard()
        k = getKeyboardBuffer()
        
        if(chrVal(k) == 10) then
            print("Bingo")
        endif
        

        Not super clean, but it works!

        1 Reply Last reply Reply Quote 1
        • Martin
          Martin Fuze Team last edited by Martin

          While you might reasonably expect "\n" to work, using chrVal is probably the correct way to do it since that is resolving the keystroke down to a single value instead of trying to compare against two values. ( '\' + 'n')

          1 Reply Last reply Reply Quote 1
          • Gothon
            Gothon F last edited by Gothon

            "\n" is the escape code for a new line character, but I noticed in a program of mine that it generated an extra character of white space. It seems it actually generates a linefeed and a space character chr(32) + chr(10), so I am not surprised that if k == "\n" then ... doesn't work for reading the keystroke.

            1 Reply Last reply Reply Quote 4
            • First post
              Last post