I don't know, if that is a good way, maybe it is slow, because of the strings I used, but dealing with numbers which can be different depending on the input device is a little bit uncomfortable.
So my idea is as follow:
Global FenBtnStr as String[12]=["AB","BB","DP","LB","LP","RB","RP","SE","ST","UP","XB","YB"]
Global FenBtnXIn as Integer[12]=[ 1, 2, 16, 5, 13, 6, 15, 7, 8, 14, 3, 4]
Global FenBtnUSB as Integer[12]=[ 3 , 2, 0, 5, 0, 6, 0, 9, 10, 0, 4, 1]
//Global FenBtnStr as String[12]=["UP","DP","LP","RP","XB","YB","AB","BB","ST","SE","LB","RB"]
//Global FenBtnXIn as Integer[12]=[14, 16, 13, 15, 3, 4, 1, 2, 8, 7, 5, 6]
//Global FenBtnUSB as Integer[12]=[ 0 , 0, 0, 0, 4, 1, 2, 3, 9, 10, 5, 6]
Function GetFenJoystickButtonState(JoyStick as integer, Btn$ as String)
State = 0
If GetRawJoystickName(JoyStick)="XInput Device" // XBox 360 Controller
If FenBtnStr.find(Btn$)>-1
State = GetRawJoystickButtonState(JoyStick,FenBtnXIn[FenBtnStr.find(Btn$)])
EndIf
ElseIf GetRawJoyStickName(JoyStick)="usb gamepad " // EXLENE SNES-Like
If Btn$ = "UP" and GetRawJoystickY(JoyStick)<-0.9
State = 1
ElseIf Btn$ = "DP" and GetRawJoystickY(JoyStick)> 0.9
State = 1
ElseIf Btn$ = "LP" and GetRawJoystickX(JoyStick)<-0.9
State = 1
ElseIf Btn$ = "RP" and GetRawJoystickX(JoyStick)> 0.9
State = 1
Elseif FenBtnStr.find(Btn$)>-1
If FenBtnUSB[FenBtnStr.find(Btn$)]<>0
State = GetRawJoystickButtonState(JoyStick,FenBtnUSB[FenBtnStr.find(Btn$)])
EndIf
EndIf
EndIf
EndFunction State
With this "mapping" the D-pads and the button layout is the same on both controller-types. I guess, any USB generic gamepad could be different, and also this idea would need not only "state", but also "pressed" and "released".
The XBox 360 controller D-pad behaves like it would be seperate buttons, the D-pad on the SNES-like gamepad is morelike it would be a joystick, but without real analoge values.