I’m writing a GUI tool to create gamepad mappings from the RAW gamepad input. The detector looks for a single input by counting all the gamepad_buttons
, gamepad_axis
, and gamepad_hats
where math.abs(value)
is greater than a small threshold. If exactly one input is detected it can then create the mapping for it.
However, when a hat
is present, it seems that there is always a button
also present (at least on all the controllers I have physical access to for testing). I have this code to detect this case, after looping through and counting all the inputs:
-- Hats seem to be remapped buttons, so when a hat is present a button will also be present.
-- That is also why hats are counted last - so that the detected_data will be the hat.
if hats_count == buttons_count then
buttons_count = buttons_count - hats_count
end
local input_count = axis_count + buttons_count + hats_count
Is this a sufficient check? Or is it also possible that hats might be sometimes remapped from an axis value, and I need to handle that case too?