Add API to get the input device an input belongs to

As a Roblox developer, it is currently too hard to know what input device a given Enum.KeyCode/Enum.UserInputType belongs to.

I want to know the device an input belongs to so that I can display it only if its device is being used. This is useful for games that support rebinding because they can’t hardcode which device inputs belong since the inputs change. Currently, I have to manually hardcode which device a KeyCode/UserInputType belong to.

If Roblox is able to address this issue, it would improve my development experience because I would be able to show UI help prompts for which input to press.

API Suggestion

UserInputService:GetDeviceFromInput(input: Enum.KeyCode | Enum.UserInputType): Enum.InputDevice

To support this API, we need a way to describe each input device. For example:

Enum.InputDevice.Keyboard
Enum.InputDevice.Mouse
Enum.InputDevice.Gamepad

Enum.UserInputType has been used in the past for APIs like UserInputService:GetLastInputType() but it doesn’t have a way to describe the mouse, for example.

Note

I’m not asking for this exact API, it’s just to explain what I’m asking for.

Another Usecase

It could be used to filter inputs when a user is rebinding an action. With this API I could make sure that whatever input they choose, it has to belong to the Keyboard.

9 Likes

While I’m not a Roblox staff

I have a solution, which uses the same method Roblox uses to determine input device. I’ll open source it and post it here later once finished