Skip to content

Instantly share code, notes, and snippets.

@clofresh
Created January 20, 2014 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clofresh/8531100 to your computer and use it in GitHub Desktop.
Save clofresh/8531100 to your computer and use it in GitHub Desktop.
-- Love debugging app for discovering joysticks
--
pressed = {}
function love.draw()
local x = 100
local y = 100
local dx = 12
local joysticks = love.joystick.getJoysticks()
for i, joystick in pairs(joysticks) do
local id, instanceid = joystick:getID()
love.graphics.print(joystick:getName() .. '(' .. joystick:getGUID() .. ':' .. instanceid .. ')', x, y)
y = y + dx
local isGamepad = joystick:isGamepad()
if isGamepad then
love.graphics.print("isGamepad? true", x, y)
else
love.graphics.print("isGamepad? false", x, y)
end
y = y + dx
local supportsVibration = joystick:isVibrationSupported()
if supportsVibration then
love.graphics.print("isVibrationSupported? true", x, y)
else
love.graphics.print("isVibrationSupported? false", x, y)
end
y = y + dx
local numAxes = joystick:getAxisCount()
for axis = 1, numAxes do
local direction = joystick:getAxis(axis)
love.graphics.print('axis ' .. axis .. ': ' .. direction, x, y)
y = y + dx
end
local numHats = joystick:getHatCount()
for hat = 1, numHats do
local direction = joystick:getHat(hat)
love.graphics.print('hat ' .. hat .. ': ' .. direction, x, y)
y = y + dx
end
local buttons = pressed[instanceid]
if buttons then
for button, isPressed in pairs(buttons) do
local isPressedStr
if isPressed then
isPressedStr = 'pressed'
else
isPressedStr = 'unpressed'
end
love.graphics.print('button ' .. button .. ': ' .. isPressedStr, x, y)
y = y + dx
end
end
y = y + dx
end
end
function love.joystickpressed(joystick, button)
local id, instanceid = joystick:getID()
if pressed[instanceid] then
pressed[instanceid][button] = true
else
pressed[instanceid] = {[button] = true}
end
end
function love.joystickreleased(joystick, button)
local id, instanceid = joystick:getID()
if pressed[instanceid] then
pressed[instanceid][button] = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment