Detecting z-axis value on joystick

I have two joystick issues in SDL2 (2.0.5 and 2.0.8 tested):

  1. How do I determine which axis is the ‘z-axis’ (as defined by the USB HID) on a particular joystick?

  2. How do I read the value from that axis without using events (ie, poll the value)?

The reason for this is that I’m trying to support a 2600-daptor D9 ( in Stella, the Atari 2600 emulator.

This device places a constant value on the z-axis, which is used to differentiate the device plugged into it, and what the DIP switches are set to. The value never changes, so no event will ever be generated. Since the z-axis is 8-bit, possible values are from 0 -255.

At first I thought that simply reading with SDL_JoystickGetAxis(), but on this device, it returns all 0’s in Windows 10 for all 4 axes. And on Linux it seems to read all -32768.

So I’m back to the original issue. How do I know which axis is the z-axis, and why doesn’t SDL_JoystickGetAxis() report a valid value??


Steve A.

Stella maintainer

Regarding getting an updated value without using events: have you tried calling ?

Regarding “How do I determine which axis is the ‘z-axis’ (as defined by the USB HID) on a particular joystick?”
Currently you can’t.
And for most use cases, this wouldn’t be particularly interesting/helpful anyway, because joystick (-like input) do what they want anyway and the USB HID value usually has no relation to reality, i.e. it’s totally random (from device to device) which physical axis of your gamepad or joystick or steering wheel or whatever map to GUID_XAxis or GUID_ZAxis or GUID_RxAxis or …
So exposing that information in SDL could confuse developers into making assumptions about those axes that would only confuse their users… Input devices are the worst.

On the other hand, I too have a usecase for this information: For a game I’m working on we’d like to provide standard bindings for common input devices (esp. gamepads and steering wheels), and right now we need to do this separately for Linux vs Windows because the engine-specific IDs are different: On Windows it uses the DirectInput wUsagePage and wUsage, on Linux/SDL it uses similar looking IDs, but just counts them up based on SDLs ordering of the axes and buttons.
So, assuming that the USB HID values are the same on Windows and Linux (and hopefully other applicable platforms like the OSX and the BSDs) - are they? - getting them from SDL would be quite useful for me as well - just as crossplatform identifiers for device-specific mappings (we could even provide meaningful names for the devices’ axes/buttons then).