Hi Developers,
We recently announced that Roblox will be widely available to users on PlayStation on October 10. We also announced that we will be upgrading the Roblox Xbox app, enabling a new look, frequent updates (with access to the latest features), improved content recommendations, and an improved user experience. This opens up another opportunity for you to create and share your experiences with millions of people instantly on Xbox and soon, PlayStation.
We are excited to bring you two APIs to help make sure your experiences can easily support gamepad icons.
- Updated UserInputService:GetStringForKeyCode to support Gamepad KeyCodes.
- New API UserInputService:GetImageForKeyCode
These changes will initially work on Xbox, PlayStation, and Windows (using a gamepad), with other platforms planned in the future. Please note that calling these APIs on other platforms will return a default mapping/image for the KeyCode.
Try it now!
Connecting a PlayStation 4 Controller to Studio on Windows will allow you to test and see PlayStation icons with these APIs today! Please use this to test your experiences and update them ahead of the PlayStation launch!
Studio also has a PS4 emulation mode that you can use alongside these APIs to test.
GetStringForKeyCode:
This API currently exists to help developers translate the US query KeyCodes to other keyboard layouts. It has been updated to support Gamepad KeyCodes. This will take the KeyCode provided and map it based on the most recently connected gamepad type. If the connected controller is not supported, the function returns the default string conversion for the requested key code.
Controller Mapping:
These mappings are also how the PlayStation controller is mapped to the Roblox KeyCodes. For example, if you want a user to press ButtonTriangle
, you should use KeyCode.ButtonY
.
KeyCode | PlayStation Return Value | Xbox Return Value |
---|---|---|
KeyCode.ButtonA | ButtonCross |
ButtonA |
KeyCode.ButtonB | ButtonCircle |
ButtonB |
KeyCode.ButtonX | ButtonSquare |
ButtonX |
KeyCode.ButtonY | ButtonTriangle |
ButtonY |
KeyCode.ButtonL1 | ButtonL1 |
ButtonLB |
KeyCode.ButtonL2 | ButtonL2 |
ButtonLT |
KeyCode.ButtonL3 | ButtonL3 |
ButtonLS |
KeyCode.ButtonR1 | ButtonR1 |
ButtonRB |
KeyCode.ButtonR2 | ButtonR2 |
ButtonRT |
KeyCode.ButtonR3 | ButtonR3 |
ButtonRS |
KeyCode.ButtonStart | ButtonOptions |
ButtonStart |
KeyCode.ButtonSelect |
ButtonTouchpad and ButtonShare
|
ButtonSelect |
Example:
This example shows how you can map custom assets for KeyCode.ButtonA.
local userInputService = game.UserInputService
local imageLabel = script.Parent
local key = Enum.KeyCode.ButtonA
local mappings = {
ButtonA = "rbxasset://BUTTON_A_ASSET", -- Replace with the desired ButtonA asset
ButtonCross = "rbxasset://BUTTON_CROSS_ASSET" -- Replace with the desired ButtonCross asset
}
local mappedKey = userInputService:GetStringForKeyCode(key)
local image = mappings[mappedKey]
imageLabel.Image = image
Notes:
- Directional pad KeyCodes do not have any differences and will map to their
Enum.KeyCode.Name
value. - KeyCode.ButtonSelect has slightly different behavior in some cases. Use both PlayStation mappings to ensure users see the correct buttons.
GetImageForKeyCode
If you don’t want to use the above API, you can use GetImageForKeyCode. This API is much simpler. This API will return a Roblox provided icon for the requested key code. This API is more geared for developers who just want it to work and can be slotted in alongside existing code for easy drop in replacement. The mapping rules will be the same as the above table.
Example:
local userInputService = game.UserInputService
local imageLabel = script.Parent
local key = Enum.KeyCode.ButtonA
local mappedIcon = userInputService:GetImageForKeyCode(key)
imageLabel.Image = mappedIcon
Known Issues:
- The APIs will not work on iOS or Android, a fix is currently pending.
- The images do not fully fill the image rectangle, this will be fixed soon.
Feedback
The API was the top request we received from the community on this feature.
If you have additional feedback or issues, please reply with the details in a comment on this post. Also, if you use these APIs in your experience, please leave a link to it below as we’d like to test it out in your game!
We are particularly interested in hearing whether you were interested in this feature and if the API suits your needs.
Your feedback will help us continually improve this feature.
Thank you.