Virtual Keyboard Script

I’ve been working on a little test game recently, and realized if I want mobile support, I need a whole virtual keyboard. I’m trying to make it literally emulate clicking a character such as E on a real PC keyboard. There already is a game on Roblox with this concept and I tried to make it months ago, it didn’t work. I made a recording as an example of what I’m looking for.

So… what is the issue?

We can’t just spoonfeed you the entire code for it

1 Like

Sorry, let me get that.

for i,v in ipairs(Keys:GetChildren()) do
  v.MouseButton1Down:Connect(function()
     Remote:FireServer({Enum.KeyCode[string.upper(v.Text)]})
  end)
end

by the way this script is a local script.
It doesn’t provide any console errors so I don’t know what’s wrong.

Try putting a print inside the event handler

It does return a print, however, nothing else is returned
image

What exactly is going wrong? Also, we’ll probably also need the server script

The issue I’m getting is that absolutely nothing is happening. The script is intended to quite literally emulate what happens when you click a key on a real keyboard. Like, if theres a keybind for E, clicking the E button would do it.

also, you cant fire client from a server script.

You don’t need to send the keybind to the server then. Just emulate the keybind locally, and whatever the keybind does has the responsibility of firing the server instead.

I don’t even know what happened or went wrong here


image

I realize now that it’s FireClient(), for this you have to put the player as the first parameter then put the second parameter is the information you’re sending.

Remote:FireClient((Player To Send To), {Enum.KeyCode[string.upper(v.Text)]})

how would you define the player? Make a plr variable and use it or…?

Your first problem is getting the clicks on the server and then firing the key to client, this is pointless since you can just use a local script and avoid having to use remote events. Through a local script you’ll also be able to just grab the local player through game.Players.LocalPlayer

my issue is that i wouldn’t know how to “not” use the remote event. if i remove it theres an error and i cant do anything about it, im still extremely new to lua

the remote event is just passing the info to the client. So if you change the script to something like this (local script):

local Keys = script.Parent.Parent

for i,v in ipairs(Keys:GetChildren()) do
  v.MouseButton1Down:Connect(function()
     local key = Enum.KeyCode[string.upper(v.Text)]
     --use the key for whatever
  end)
end

you can handle the key clicks on client without the remote event

thats exactly what i was looking for! however, im still trying to make it emulate a PC keyboard click, any idea how i’d make that function

From what I know I don’t think there is anything that allows you to do this. You’d have to manually fire the functions to do this.

*cough* *cough* ContextActionService:BindAction()

Hey! I just finished creating a module that I think can help you with your problem:
Input Service V2

Using this you can simulate moving forward and also simulate other keys

2 Likes

oh my gosh thank you so much i needed this

o ma gad tjws admin house im a rank 7