Res: Add example gamepad demo

This commit is contained in:
Vicki Pfau 2023-01-26 04:20:36 -08:00
parent 0dd7cfd44a
commit a62a3eb811
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
inputBuffer = console:createBuffer("Input")
function readPad()
inputBuffer:clear()
if not input.activeGamepad then
inputBuffer:print("No gamepad detected\n")
return
end
local gamepad = input.activeGamepad
local axes = gamepad.axes
local buttons = gamepad.buttons
local hats = gamepad.hats
inputBuffer:print(string.format("%i buttons, %i axes, %i hats\n", #buttons, #axes, #hats))
local sbuttons = {}
for k, v in ipairs(buttons) do
if v then
sbuttons[k] = "down"
else
sbuttons[k] = " up"
end
end
inputBuffer:print(string.format("Buttons: %s\n", table.concat(sbuttons, ", ")))
inputBuffer:print(string.format("Axes: %s\n", table.concat(axes, ", ")))
inputBuffer:print(string.format("Hats: %s\n", table.concat(hats, ", ")))
end
callbacks:add("frame", readPad)