1
readtext() can sort of do what you want, but it only works for text-input keys. (peektext and readtext are similar to stat 30/31 from pico8)
function _draw() a=readtext() if a then print("text: "..a) end end |
2
After looking at the code in system/lib/events.lua some more I realised you can add your own event handler.
function _init() anykey = false on_event("keydown", anykey_handler) on_event("keyup", anykey_handler) end function anykey_handler(msg) if msg.event == "keydown" then anykey = true else anykey = false end end |
Then you can check if anykey is true later in your code.
You can also do something like this:
function _init() pressed_key = nil end function _update() pressed_key = nil for i = 0, 284 do if key(i) then pressed_key = i return end end end function _draw() cls() print(pressed_key) end |
pressed_key will be one of the sdl2 scancodes, you can check all of them here: https://wiki.libsdl.org/SDL2/SDLScancodeLookup
[Please log in to post a comment]