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.

1


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]