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

How do I check if they player presses ANY key?

Asked by 5 years ago

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.

0
Use UserInputService User#24403 69 — 5y

1 answer

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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)
Ad

Answer this question