How would I make a mobile button press down a computer key?

I want to make a mobile button that presses a computer key.
I’ve tried many solutions from people with the same problems as me and also tried a the mobile button page. I only need this because I want to add mobile support to a game i’m creating,

Here is some code from the creating mobile page that I tried but didn’t work. (it creates the button but doesn’t press a key down when pressed)

1. local ContextActionService = game:GetService("ContextActionService")
 * local function handleAction(actionName, inputState, inputObject)
2. if inputState == Enum.UserInputState.Begin then
3. print(actionName, inputObject)
4. end
5. end
 * -- Bind action to function
6. ContextActionService:BindAction("Interact", handleAction, true, Enum.KeyCode.T, Enum.KeyCode.ButtonR1)

There is no way to emulate a key press from a click event. However, what you could do is fire the same code that would run when you click the key, but instead with the button GUI.

Also, use Remote events, they are a life saver!

2 Likes

Alright!
Ill try that and see if it works! :smiley: