Gamepad APIs: Cross-Platform Button Support

Unfortunately the official way to override button images via userInputService:GetStringForKeyCode won’t work if you want to be able to distinguish between PS4 and PS5 buttons like the share button.

A workaround is to use userInputService:GetImageForKeyCode instead since it returns a different button image for PS4 and PS5.

e.g.

local mappings = {
    ["rbxasset://textures/ui/Controls/PlayStationController/PS4/ButtonShare@2x.png"] = "rbxasset://PS4_SHARE_BUTTON_ASSET",
    ["rbxasset://textures/ui/Controls/PlayStationController/PS5/ButtonShare@2x.png"] = "rbxasset://PS5_SHARE_BUTTON_ASSET"
}

local mappedKey = userInputService:GetImageForKeyCode(key)
local image = mappings[mappedKey] or mappedKey

imageLabel.Image = image

Not the safest way since if roblox decides to change the image path then it’ll fail, though at worst it’ll just revert back to using the default image supplied by roblox.

1 Like

PlayStation 5 controller should be supported.

1 Like

In the drop down for the emulated type, there should be PS4. Please ensure you’re on the latest studio.

1 Like

This would work I agree but is not the cleanest solution, I’ll leave a ticket to investigate it more.

@MauroNr1 this answers your middle question too.

As for the triggers and gyroscope, those are not currently supported.

1 Like

What should expect emulating ps5 , like in same behavior of emulating ps4 ? I’d that would be cool if everyone would kindly emulating ps4 and ps5 at what best at kind.

Thanks for releasing these APIs for public use my games are now ready for PlayStation release tomorrow! Also, how do I make the controller rumble?

After uninstalling and reinstalling Roblox Studio, I still don’t see PS4 as an option.

Image of device emulator dropdown

Version Info:
image

Maybe it’s not on public release. It could just be a bug on my end though.

I’m having the same issue, on the same version. Would love to have a solution soon since playstation release is tomorrow.

Hello, I noted that the PS4 option doesn’t appear if I opt-in to the beta Notched Screen Support.

Opt-In
image
image

Opt-Out
image
image

6 Likes

Ah, will you plan to support controller gyroscope in the future? I was hoping for this to be added day 1 so developers can implement gyro aiming in their first person shooter games. Energy Assault already has gyro aiming on mobile devices.

1 Like

I think most people don’t see a game app on ps4 console like i cannot see myself on brothers ps4 console, and i think that problem persist me from not having a ps4 pro, we only have normal ps4, and that’s how the problem occured when i don’t see it on playstation store :slightly_frowning_face:

because it hasnt dropped yet drops in 1 hour they said 5cst on my ps app so meaning i got 1 hour and 30 minutes

1 Like

Is it intentional for the selections w/ controller for UI to break if a billboard GUI is attached to an attachment?

You get a warning in output when attempting to select said GUI “Setting GuiService.SelectedObject to invalid GuiObject” and still select the desired object, but can not select any adjacent GUI’s even if you provide a selection group or provide left/right/up/down directions

Can we bring back the music on ps and xbox menu like you heard before if mostly relieved my likeness for music back again, i don’t think it will work on new music but in different synchros, i don’t think would take it far back like from 2016, and i think it would been fit pretty cool through the menu back again for music is like a taste.

Off topic, but rumble doesn’t work on the ps5 controller. I have to use an Xbox controller emulator for it to work, but then the icons are back to the Xbox ones.

I want a feature that allows you to change text labels on each console.

Hi @NoUniqueAddress,

I’m trying to use this API to effectively support non‑QWERTY keyboards, QWERTY keyboards, and gamepads as you show in the OP. However, when using my QWERTY keyboard, with the API, it returns a blank string. I do not have access to an non‑QWERTY keyboard.

Printing this:

UserInputService:GetStringForKeyCode(Enum.KeyCode.LeftShift)

Gives me this:



Here’s an example of the issue:

image

I thought this was a bug, but it’s apparently intentional behavior. To respond to @idevride here, my expectation is that the Enum.Keycode prints to the correct button for the user to press no matter what keyboard or gamepad they have. I shouldn’t have to check if the user has a non‑QWERTY keyboard or if they have a different gamepad. If I have a QWERTY keyboard, LeftShift should return “LeftShift”.

Here’s a feature request about the issue, from 2022: Expand Keys for UserInputService:GetStringForKeyCode. The OP there assumes the issue is a lack of support in the API for all the KeyCodes, yet the bug report I mention above would oppose that. If the intentional behavior is to print out an empty string, that should be changed. The issue with this is that I do not have access to the Feature Request categories, and yes I have requested to join the @AllowFeatureRequests group. It’s not really taking people in right now.

This issue is impacting my game and I can’t fix the issues of the wrong prompts being shown to users without making my own system. If someone at Roblox could reply to this issue as soon as possible, that’d be great.

Thanks,
Reditect


Edit 6/8/2024:

I’ve removed support for non-Qwerty keyboards from my game because of this API. I am using a Qwerty keyboard. When using the API, I get a blank string. That means my players see blank prompts in dialogue and whatnot. I’d rather support Qwerty than no keyboards at all. I am still using the API for gamepad however, that works fine.

2 Likes

Edit: here’s the feature request: Change GetStringForKeyCode() to Return the String of Keycodes


Old reply:

Bump, this is out of my control. I will continue to bump before the 4 month closing period on this topic until I (or someone else) can make a feature request or staff responds.

1 Like

this is useless. its called “Gamepad API” not “ChangeIcons API”. you can use UserInputService | Documentation - Roblox Creator Hub to do what you want to do but its only for text.

use UserInputService | Documentation - Roblox Creator Hub,

here is some code:

local UserInputService = game:GetService("UserInputService")

local textLabel = script.Parent
local mapKey = Enum.KeyCode.ButtonA
textLabel.Text = "press the " .. UserInputService:GetStringForKeyCode(mapKey) .. " to do something"

use the “Button” keycodes to change it.