Get controller layout / type from joypad device #7086
Replies: 3 comments 2 replies
-
The two lists you provided seem like exactly what's needed - some way to get the general controller type. Either that or a way in godot to set bindings for a specific device (B for Xbox controller and B for Switch controller). This might also be a good thing for an addon which maintains a list of controllers in a giant match statement like you wrote. |
Beta Was this translation helpful? Give feedback.
-
Made trivial by implementing #9000 see |
Beta Was this translation helpful? Give feedback.
-
FYI: I use the following as a pragmatic solution for now enum Input_methods_layouts { GENERIC_GAMEPAD, XBOX_360, XBOX_ONE, XBOX_SERIES, PS4, PS5, SWITCH, SWITCH_PRO, STEAM_DECK}
func get_device_layout_from_device_name(device_name:String) -> int:
# --- Xbox ---
if contains_any_of(device_name, ["xbox"]):
if contains_any_of(device_name, ["series"]):
return Input_methods_layouts.XBOX_SERIES
if contains_any_of(device_name, ["one"]):
return Input_methods_layouts.XBOX_ONE
if contains_any_of(device_name, ["360"]):
return Input_methods_layouts.XBOX_360
return Input_methods_layouts.XBOX_SERIES # Fallback
# --- Playstation ---
if contains_any_of(device_name, ["ps5", "ps-5", "ps 5"]):
return Input_methods_layouts.PS5
if contains_any_of(device_name, ["ps4", "ps-4", "ps 4"]):
return Input_methods_layouts.PS4
if contains_any_of(device_name, ["playstation", "play station", "play-station"]):
if contains_any_of(device_name, ["5", "five"]):
return Input_methods_layouts.PS5
if contains_any_of(device_name, ["4", "four"]):
return Input_methods_layouts.PS4
return Input_methods_layouts.PS5
# --- Steam Deck ---
if contains_any_of(device_name, ["steam"]):
if contains_any_of(device_name, ["deck"]):
return Input_methods_layouts.STEAM_DECK
# We Steam gamepad will fallback to generic
if contains_any_of(device_name, ["switch"]):
if contains_any_of(device_name, ["pro"]):
return Input_methods_layouts.SWITCH_PRO
return Input_methods_layouts.SWITCH
return Input_methods_layouts.GENERIC_GAMEPAD
func contains_any_of(compare_string:String, strings:Array[String]) -> bool:
# ToDo: Replace with containsn once available
var lowercased_string := compare_string.to_lower()
for string in strings:
if lowercased_string.contains(string):
return true
return false |
Beta Was this translation helpful? Give feedback.
-
Context:
In my game I want to show an appropriate image depending on which controller the player has plugged in. E.g.: If it's any type of PS5 controller, show an image of a PS5 controller.
Problem:
There are many controllers that share the same layout but have different names or IDs. (e.g. an original PS4 controller and a "knock off" third party controller)
Solution
Create a document referencing IDs or names from SDL_GameControllerDB with a value that describes a controller's/joystick's basic layout, e.g.
xbox-series-controller
orwii-remote
. (This is not the same as the controller's platform, as explained below.)This could then be used with Godot (or another engine for that matter). It could even be exposed via Godot directly as something like
get_joy_layout(int device)
analog to get_joy_name.Complications (only one example each):
Different brand but same layout: The "8Bit Do Zero"-controller looks different from a regular "SNES controller", but fundamentally they are the same
→ Both should be
snes-controller
Added features: An "Xbox Elite Controller" is the same as an "Xbox Series Controller", but has additional buttons like paddles
→ Tricky, but
xbox-series-controller
for both would likely be fineAdjusted layout: Hori Fighting Commander Xbox 360 is an Xbox 360 controller but has a slightly different layout
→ Tricky, could be considered
xbox-360-controller
but also not (I'd argue less granularity in this use case is preferable)Same platform, multiple controllers: The Nintendo Switch has a "Switch Pro Controller" and "Joycons"
→ Value would be
switch-pro-controller
andjoycon-pair
, despite having the same buttons because their appearance is very differentMultipurpose-controllers: The Nintendo Switch's "Joycons" can be used as pair or individually
→ Values would be
joycon-pair
,joycon-right
andjoycon-left
(this case might not be coverable by the DB because likely Joycons are connected individually to a computer)Controller and computer are one device:
steam-deck
would be a value because it's a controller in itself (unlikesteam-controller
which is just a controller)Totally unique controllers: "Microsoft dual strike" or the "DK Bongos" deviate a lot from the normal controller
→ Don't share a layout with other controllers, would return
null
A possible (and incomplete list) of values could be:
ps-controller
,ps2-controller
,ps3-controller
,ps4-controller
,ps5-controller
,xbox-controller
,xbox-360-controller
,xbox-series-controller
,xbox-one-controller
,joycon-right
,joycon-left
,joycon-pair
,steam-deck
,steam-controller
,wii-remote
,gamecube-controller
,ouya-controller
,luna-controller
,snes-controller
and so on.If I had to do this only for my game for a few dozen controllers, I'd likely do it this way (incomplete)
Why discussion?
I opened this as discussion because technically it's a problem independent of Godot, so I am not sure how best to approach it. It seems to me this problem should be fairly common, so a community solution would be awesome to make it easer for everyone.
Research
Beta Was this translation helpful? Give feedback.
All reactions