How can you make when you press a gui button it is detected as a key?

How could you make when a gui button is pressed it detects it as a key? is that I need this to add it to mobile because what I have is necessary to do this

2 Likes

Not really sure what you mean but sounds like you’re looking for InputChanged on GuiObjects. The input a user passes on the GuiObject will be sent as an InputObject describing the nature of the input.

because when a player touches the button text it becomes a key, that the input is that of a key

I’m sorry but this doesn’t help me understand the problem. The wording is vague and I don’t have any reference material, so I don’t understand exactly what you’re looking to do. Are you trying to convert mobile input to a key press? I need details. Pictures would help as well, such as what you want it to do and what it’s currently doing/not doing.

image

Oh I see, thanks, this helps out.

What you could do is map out the action that should occur when the user presses the button or the R key and then when either that button is pressed or the R key is pressed then you run the function for that action. ContextActionService can handle this for you, although there are complaints that the gui button functionality is rather finnicky.

local ContextActionService = game:GetService("ContextActionService")

local ACTION_NAME = "MyAction"
local ACTION_KEY = Enum.KeyCode.R

local function actionFunction(actionName, inputState, inputObject)
    if actionName == ACTION_NAME then
        print("Action that the R key triggers was pressed")
    end
end

ContextActionService:BindAction(ACTION_NAME, actionFunction,  true, {ACTION_KEY})

Besides ContextActionService, you can make your own controller map to handle input from the user. You can then map the button press to commit the same action as if you pressed the R key. Typically it’s best if you design for mobile controls without equating them to keyboard action since mobile is a whole lot more limited in its one-time input ability.

4 Likes

I know it’s been 21 days, but does anyone know how to do this the other way around?

i need a tutorial about this, because im new to roblox studio