Gamepad APIs: Cross-Platform Button Support

Ahh I misunderstood, I thought which gamepad device type, XboxController, PlayStationController etc. If you’re talking about Mobile/Console/PC then yeah we don’t expose the device type and currently there are no plans to. Generally we want developers to program for an input method as you can have a wide variety of devices with the same input method. For example a controller can be used on all platforms, console, mobile and PC. Your request is a much bigger topic, I suggest posting over on feature requests for this.

Thanks for the explanation!

6 Likes

I can see how its confusing to VR but most people skilled enough to make VR games will use the face button names

Enum.KeyCode.ActionButtonUp
Enum.KeyCode.ActionButtonDown
Enum.KeyCode.ActionButtonLeft
Enum.KeyCode.ActionButtonRight

these keycodes not only differentiate themselves from the dpad but also solve the issue of not knowing how to quickly convert from the different formats to whatever non-copyrighted symbol an offbrand controller may use (or different button layout)

6 Likes

I’d love to see a demo/link to this place. I’ve yet to see someone on Roblox build a split screen experience and unfortunately it would be limited to just PC. As far as I know, consoles do not support more than one connected controller? This is an interesting use case though, will think about it. Thanks

13 Likes

Roblox officially supports up to 8 controllers, it’s only reasonable to assume that these APIs should do the same, in very rare circumstances local multiplayer games are made with multiple gamepads which would benefit from this.

10 Likes

@2jammers @AdvancedOpenGL

Yeah unfortunately these names will still run into issues especially with VR controllers. How do you label up/down/left/right when the buttons are split two on either controller. I understand your frustration with the current abxy layout but for now we’d rather not expose more KeyCodes and have to maintain those as well long term. We don’t want to trade one set of problems for another.

One solution that could be discussed is a higher level input system to not have to worry about these mappings but that’s a different project that would need to be thought through.

I appreciate the concern though, we’re definitely aware of this pain point.

7 Likes

This is awesome to see. Of course, this means some work for me, but it’s overall a good thing.


This is my implementation before this update:
local userInputService = game:GetService("UserInputService")
local InputTypeChangedRE = game.Workspace.RemoteEventsFolder.Inputs.InputTypeChanged

local mouseInputType =
	{
		Enum.UserInputType.MouseButton1,
		Enum.UserInputType.MouseButton2,
		Enum.UserInputType.MouseButton3,
		Enum.UserInputType.MouseMovement, 
		Enum.UserInputType.MouseWheel	
	}

local mobileInputType = Enum.UserInputType.Touch

local XboxControllerInputsList = {
	Enum.KeyCode.Thumbstick1,
	Enum.KeyCode.Thumbstick2,

	Enum.KeyCode.ButtonA,
	Enum.KeyCode.ButtonB,
	Enum.KeyCode.ButtonX,
	Enum.KeyCode.ButtonY,

	Enum.KeyCode.ButtonL1,
	Enum.KeyCode.ButtonL2,
	Enum.KeyCode.ButtonL3,

	Enum.KeyCode.ButtonR1,
	Enum.KeyCode.ButtonR2,
	Enum.KeyCode.ButtonR3,

	Enum.KeyCode.ButtonStart,
	Enum.KeyCode.ButtonSelect,

	Enum.KeyCode.DPadUp,
	Enum.KeyCode.DPadDown,
	Enum.KeyCode.DPadLeft,
	Enum.KeyCode.DPadRight,

}

local PS4ControllerInputs = {
	
}
-- "PS4Controller"




local UserInputTypeSystemModule = {}

UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse" --keyboard mouse is default


userInputService.InputBegan:Connect(function(input)
	-- print("InputType Test: "..inputTypeThePlayerIsUsing)

	-- Computer Input / Keyboard & Mouse: --
	if input.UserInputType == Enum.UserInputType.Keyboard then -- Keyboard inputs --
		if UserInputTypeSystemModule.inputTypeThePlayerIsUsing == "Xbox" or UserInputTypeSystemModule.inputTypeThePlayerIsUsing == "Mobile" then
			print("New InputType detected: Keyboard and Mouse")
			UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse"
			InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
			userInputService.MouseIconEnabled = true
			script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
			return
		end
	end
	for i, mouseInputs in pairs (mouseInputType) do -- Mouse inputs --
		if input.UserInputType == mouseInputs  then
			if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "KeyboardAndMouse" then
				print("New InputType detected: Keyboard and Mouse")
				UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse"
				InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
				userInputService.MouseIconEnabled = true
				script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
				return
			end
		end
	end


	-- Xbox Input: --
	if input.UserInputType == Enum.UserInputType.Gamepad1 then -- Gamepad Inputs --
		if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Xbox" then -- if the inputType isn't already xbox, make it.
			print("New InputType detected: Xbox")
			UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Xbox"
			InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
			userInputService.MouseIconEnabled = false
			script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
			return
		end
	end
	for i, xboxInputs in pairs (XboxControllerInputsList) do -- Controller button inputs --
		if input.UserInputType == xboxInputs  then
			if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Xbox" then
				print("New InputType detected: Xbox")
				UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Xbox"
				InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
				userInputService.MouseIconEnabled = false
				script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
				return
			end
		end
	end

	-- Mobile Input / Touchscreen input: --
	if input.UserInputType == Enum.UserInputType.Touch then
		if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Mobile" then -- if not mobile/touch input already, make it.
			print("New InputType detected: Mobile")
			UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Mobile"
			InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
			script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = true
			
			local JumpButton_Path = script.Parent.TouchGui.TouchControlFrame:WaitForChild("JumpButton")
			JumpButton_Path.Position = UDim2.fromScale(0.845, 0.715)
			--JumpButton_Path.Size = UDim2.new(JumpButton_Path.Size.X*1.2,JumpButton_Path.Size.Y*1.2)
			
			local ToggleMobileButton_RemoteEvent = game.Workspace.RemoteEventsFolder.UI.ToggleMobileButtons
			ToggleMobileButton_RemoteEvent.OnClientEvent:Connect(function(whatButtonShouldBeToggled,toggleState)
				if whatButtonShouldBeToggled == "JumpButton" then
					if toggleState == false then
						JumpButton_Path.Visible = false
						print("Mobile Jump button toggled OFF")
					elseif toggleState == true then
						JumpButton_Path.Visible = true
						print("Mobile Jump button toggled ON")
					end
				end
			end)
			
			return
		end
	end
	
	-- PS4 Inputs:
	

end)

return UserInputTypeSystemModule


local InputTypeChangedRE = game.Workspace.RemoteEventsFolder.Inputs.InputTypeChanged


InputTypeChangedRE.OnServerEvent:Connect(function(player,whatInputTypeIsThePlayerUsing)
	if whatInputTypeIsThePlayerUsing == "KeyboardAndMouse" then	
		script.Parent.XboxInput.Visible = false
		script.Parent.KeyboardsInput.Visible = true	
		script.Parent.mobileInput.Visible = false
	elseif whatInputTypeIsThePlayerUsing == "Xbox" then
		script.Parent.XboxInput.Visible = true
		script.Parent.KeyboardsInput.Visible = false
		script.Parent.mobileInput.Visible = false
	elseif whatInputTypeIsThePlayerUsing == "Mobile" then
		script.Parent.XboxInput.Visible = false
		script.Parent.KeyboardsInput.Visible = false
		script.Parent.mobileInput.Visible = true
	end
end)


There are probably some bad practices throughout the code, but it worked. With PS4 coming, I wondered how I’d show the correct inputs to players. I’ll make another reply here after my implementation of the updated system to share my feedback on it.


I’d like to make a local multiplayer party game sometime in the future, one that requires multiple controllers. That’s after I finish my current project though, so I don’t know what the local multiplayer game would look like. It’s only an idea really.

5 Likes

Amazing, and with the inclusion of default playstation buttons we can detect what platform a user is on! This is an AMAZING update.

6 Likes

Please note that a PlayStation controller can currently be used on other platforms such as Mac/Windows/Android/iOS etc.

6 Likes

@Reditect @Abcreator @2jammers

Local multi controller games are currently a low priority and I’m not sure are still well supported or maintained. I’ll keep this in mind to take a look at, but I can’t promise anything will come from it.

8 Likes

I’ll send a place file in a couple hours. I used to have the place but I believe I changed it.

It’s okay tho, I wanna change it again.

Also this is fine, I think the APIs we currently have are already enough to support this.

4 Likes

– north, south, east west are much better names imo 'cause they differentiate it from the dpad better

4 Likes

I never remember my directions, wouldn’t work well name wise

5 Likes

Would appreciate early access to this as well to make sure everything is working correctly.

5 Likes

Would it be possible for in the future there can be a second argument for different styles, the current icons wont fit some games for their ui styles

7 Likes

Yes, these assets will be correctly updated for the PlayStation launch.

7 Likes

@OutlookG @CrazyCorrs

Unfortunately we cannot provide early access to PlayStation.

6 Likes

What would different styles look like? If you want custom images, beyond what you’re able to edit with the normal ImageColor3 and BackgroundColor3 I suggest you look at this example and upload your own images in whatever art style fits your experience.

5 Likes

Will the images for the roblox default UI be updated for playstation controllers soon as well? (Purchase items, proximity prompts etc)?

4 Likes

A lot of things were updated, but I will take a look at both of those. Thanks for the feedback.

6 Likes

Even so, why cant we STILL not access the Platform enum in 2023. Roblox themselves have proven their one reason for not giving it isn’t true given that the UI is different between Mobile (leaderboard), PC and consoles, even if not that, just a way to tell if the user has an Xbox or a PlayStation controller plugged in on PCs.

10 Likes