GetKeyboardBuffer - How do I detect the enter key?
-
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 :)
-
I found a way to do it
showKeyboard() k = getKeyboardBuffer() if(chrVal(k) == 10) then print("Bingo") endif
Not super clean, but it works!
-
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')
-
"\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 characterchr(32) + chr(10)
, so I am not surprised thatif k == "\n" then ...
doesn't work for reading the keystroke.