X Tutup
Skip to content

Android: Improve D-pad support for Default Android Gamepad.#112762

Merged
akien-mga merged 1 commit intogodotengine:masterfrom
Benjamin-Dobell:fix/android/dpad-support
Dec 2, 2025
Merged

Android: Improve D-pad support for Default Android Gamepad.#112762
akien-mga merged 1 commit intogodotengine:masterfrom
Benjamin-Dobell:fix/android/dpad-support

Conversation

@Benjamin-Dobell
Copy link
Contributor

@Benjamin-Dobell Benjamin-Dobell commented Nov 14, 2025

Previously the default gamepad wasn't actually setup to handle regular D-pad keycode events. Instead it had only been hooked up to hat inputs. Many Bluetooth controllers paired with recent Android versions fire keycode events for their D-pad.

I've tested 3 different models of Bluetooth controller (they're all cheap third-party Nintendo Switch gamepads), they all only fire D-pad key codes on Android OS 13.

Probably worth noting, I have not removed the hat bindings — I've just fixed support for D-pad bindings. Any controllers that are firing hat events ought to be unaffected.

Previously the default gamepad wasn't actually setup to handle
regular D-pad keycode events. Instead it had only been hooked up
to hat inputs. Many bluetooth controllers paired with recent
Android versions fire keycode events for their D-pad.
@Benjamin-Dobell Benjamin-Dobell requested a review from a team as a code owner November 14, 2025 14:53
@Chaosus Chaosus added this to the 4.x milestone Nov 14, 2025
Copy link
Member

@Alex2782 Alex2782 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good


# Android
Default Android Gamepad,Default Controller,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a4,x:b2,dpup:h0.1,back:b4,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a5,b:b1,platform:Android,
Default Android Gamepad,Default Controller,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a4,x:b2,dpup:h0.1,back:b4,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a5,b:b1,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,platform:Android,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it work when you have multiple bindings for dpup, etc.? Does it pick the first/last or does it actually support multiple ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bindings are stored in a Vector:

mapping.bindings.push_back(binding);

The first matching input will be returned:

godot/core/input/input.cpp

Lines 1521 to 1554 in 7a207b3

Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button) {
JoyEvent event;
for (int i = 0; i < mapping.bindings.size(); i++) {
const JoyBinding binding = mapping.bindings[i];
if (binding.inputType == TYPE_BUTTON && binding.input.button == p_button) {
event.type = binding.outputType;
switch (binding.outputType) {
case TYPE_BUTTON:
event.index = (int)binding.output.button;
return event;
case TYPE_AXIS:
event.index = (int)binding.output.axis.axis;
switch (binding.output.axis.range) {
case POSITIVE_HALF_AXIS:
event.value = 1;
break;
case NEGATIVE_HALF_AXIS:
event.value = -1;
break;
case FULL_AXIS:
// It doesn't make sense for a button to map to a full axis,
// but keeping as a default for a trigger with a positive half-axis.
event.value = 1;
break;
}
return event;
default:
ERR_PRINT_ONCE("Joypad button mapping error.");
}
}
}
return event;
}

However, we have duplicate outputs here, not duplicate inputs, so there's no ambiguity.

@akien-mga akien-mga modified the milestones: 4.x, 4.6 Dec 2, 2025
@akien-mga akien-mga merged commit 3d585df into godotengine:master Dec 2, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup