Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect buttons such as Enter or Delete in Keydown events?

Asked by 5 years ago

So I am basically writing a script for a player to be able to change the text of a Gui.

I want the player to be able to type, so far I have managed but I can not find a way to basically detect when the player presses Enter or Delete. I know how to program the rest when the button is pressed but when it comes to detecting it I've got no clue.

Here is the part in Global Script, It's connected through a remoteevent to a local script detecting and sending the keys pressed.

keyboards = {"--//%USERNAME:"}
function Type(player, key)
    if key == DeleteButton then
        mydeletescript()
    else
        table.insert(keyboards, key)
        PGUIFrame.ScrollingFrame.qwerty.Text = table.concat(keyboards, "")
end
script.Parent.Parent.Values.keypress.OnServerEvent:Connect(Type)

Please tell me if there is a detail I forgot to mention!

0
dont use keydown, it's deprecated. User input service instead theking48989987 2147 — 5y
0
Ok, so I was just being plain dumb and using an deprecated service. You can use the User Input Service to get stuff like this and it will work much, much better. Don't do my mistake! Tommydogs22 2 — 5y
0
Enter is Enum.KeyCode.Return, Delete is Enum.KeyCode.Delete DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
5 years ago
Edited 5 years ago

An example for UserInputService: Put a LocalScript to StarterCharacterScript and write the following code into it:

game:GetService("UserInputService").InputBegan:Connect(function(input,proc)
    if not proc and input.KeyCode == Enum.KeyCode.Return then
        print("Enter pressed") -- Of course this can be changed to what you want, you can just use FireServer() from there, and it will fire only when enter is pressed
    end
end)

Ad

Answer this question