[SDL] relying on SDL_Joystick constants ?

Patrice Mandin mandin.patrice at wanadoo.fr
Wed Sep 7 09:58:31 PDT 2005

Le Wed, 7 Sep 2005 14:04:10 +0000 (UTC)
Guillaume Denis <denis at cri.ensmp.fr> a écrit:

> I have noticed that some joysticks without analog sticks return
> JOYAXISMOTION events instead of JOYHATMOTION events. I am going to
> make a backward conversion but I was wondering if other oddities may
> happen.

You'll never know what the user will have: only 1 hat (old joysticks), 4
axis (like playstation paddles), or both (1 hat+analog paddles).

> If so, are they specific to each joystick model or are they some known
> strange behaviour that I have to deal with ?

I think is is more driver/OS specific. For example, joysticks plugged on
sound card port on PC must return analog values, even if they are
digital. In this case it is done at hardware level.

Or from my personal experience, I implemented the Atari joystick driver
as emulating an analog joystick (2-axis), because I did not know what a
hat was. Then I fixed that to match the hardware reality, which was 1

> For example, I guess not any joysticks return the same constant for L1
> button. Are there better solutions that involving the final player or
> dealing with a known database of configurations ?

Except on platforms where everyone is using the same joystick (like on
game consoles), you'll never know what button <n> is, and where it is on
the joystick. In fact, don't even consider that axis 0 is horizontal,
and axis 1 is vertical.

The solution is to make it configurable which can be a tedious task, but
it is the price to pay, to have a joystick layer independent from the

Note: I did not check for Playstation 2 paddle button stuff in SDL, but
the buttons can return an analog value, not only pressed/depressed. Does
SDL consider the buttons as on/off hardware?

Patrice Mandin
WWW: http://pmandin.atari.org/
Programmeur Linux, Atari
Spécialité: Développement, jeux

More information about the SDL mailing list