Gamepad Hats - what should be possible?

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?

Not sure what you are asking.

Each hat “button” is handled the same way as a regular button. So, our gamepads only have axis and buttons.

The code is here. It looks at the gamepad raw data, loops through all possible axis (32), button (32), and hats (4), and tries to check that one and only one input is currently being pressed.

However, whenever a hat was present there was always a corresponding button present. So I had to add the above code to ignore the button input that was present with the hat.

The question is about if this check is sufficient to handle all controller types. A counter-example might be a controller where the D-pad comes in on an axis and gets somehow mapped to the hat values. If that were the case and the raw data included a hat plus an axis, it would not be possible with the code above to detect that state, because it would be seen as two inputs not one.

I guess another thought is that, if hats are ALWAYS simultaneously mapped as buttons… what’s the point of having hats in the .gamepads files at all? Why not just use the button indices?