Log In  

How do you detect ANY keyboard key being pressed on the Picotron? btnp() returns a number if you pass no argument so you can check if it is greater than zero to see if any controller button is pressed. keyp() only returns true or false whether you pass any arguments or not.

P#145940 2024-04-07 02:42 ( Edited 2024-04-07 23:53)

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
P#145962 2024-04-07 10:13
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.

P#146008 2024-04-07 23:50

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

P#146117 2024-04-09 00:08

[Please log in to post a comment]