SDL Forum Index
Simple DirectMedia Layer Forums
Reply to topic
Identify Joystick Axis Type

Joined: 06 Feb 2017
Posts: 1
Reply with quote
Dear All,

SDL identifies the axis with an index. Usually index=0 is the X axis and 1 is the Y. The other Axis (Z,RX,RY,RZ and Slider) have not a fixed index and from the documentation of Joystick I've found no function that allows to identify the axis type from the index. For example in one joystick the index 2 is the Z in other joysticks is RX.

I've had a look at the SDL source code (function AddHIDElement) and see that the following switch statement allocates a new axis but it seems to discard the "usage" axis information:

case kIOHIDElementTypeInput_Axis: {
switch (usagePage) { /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
case kHIDPage_GenericDesktop:
switch (usage) {
case kHIDUsage_GD_X:
case kHIDUsage_GD_Y:
case kHIDUsage_GD_Z:
case kHIDUsage_GD_Rx:
case kHIDUsage_GD_Ry:
case kHIDUsage_GD_Rz:
case kHIDUsage_GD_Slider:
case kHIDUsage_GD_Dial:
case kHIDUsage_GD_Wheel:
if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
element = (recElement *) SDL_calloc(1, sizeof (recElement));
if (element) {
headElement = &(pDevice->firstAxis);

Is my analysis correct? If yes, I think adding the "usage" can be a very useful feature to add in future SDL releases, for example including in the event the property axisenum (example: e.jaxis.axisenum) to get the event axis type. This will allow the developer to setup a default joystick configuration that immediately works without doing any manual mapping (for example a flight simulator can immediately work with the basic axis types: X,Y,RZ and Slider.)

Thanks for your time and keep up the wonderful work with SDL!! Smile
View user's profileSend private message

Joined: 07 Feb 2017
Posts: 2
Reply with quote
Have you see the Game Controller API?

It will give you the usage information you require.
You can test for things like:

View user's profileSend private message
Identify Joystick Axis Type
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

 Reply to topic