Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

3 comments

0

dont use keydown, it's deprecated. User input service instead

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!

0

Enter is Enum.KeyCode.Return, Delete is Enum.KeyCode.Delete

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.