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

How do I check if they player presses ANY key?

Hello, i am making a LocalScript that detects if the player has pressed ANY button.

I want it to be any button is that Xbox and Mobile users can also press a button without needing to code extra scripts.

I already know the KeyPressed event. I just want to know how to detect if any key is pressed. Thanks.

1 comment

0

Use UserInputService

1 answer

✓ Accepted answer

You can connect to UserInputService.InputBegan and then check if KeyCode isn't Enum.KeyCode.Unknown like this:

game:GetService("UserInputService").InputBegan:Connect(function(iobj, gp)
    if gp then return end --if they are typing in a textbox or something
    if iobj.KeyCode ~= Enum.KeyCode.Unknown then
        print("a key has been pressed, woooo!")
    end
end)

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