How to detect if any key is pressed

Hello!

I am trying to detect when the player presses any key. I know how to get an input from a specific one, but not from any and could not find any articles to help.

Any solutions?

(Currently using this:)

UserInputService.InputBegan:Connect(function(inputObject)
    if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		playerGui.MenuScreen.Enabled = true
		--[[FrameTween:Play()
		wait(2)
		LoadingScreen:Destroy()]]
	end
end)
3 Likes

This looks fine! are there any errors?

None, just doesn’t work no matter what I press.

EDIT: I was stupid and found a mistake further up in the code.

Did you fix it? (30 chars limit)

Did you try using…

UserInputService.InputBegan:Connect(function(inputObject)
	print("I clicked a key!")
	-- What to put when player clicks.
end)

The .InputBegan Event fires when players type input, any if you want any key, you dont need to specify the key clicked.

4 Likes

Yes I fixed it. (30 chars limit)

Thanks! I did not know that. (30 chars limit)

Well InputBegan is for mouse and keyboard, and I think he was trying to track only the keyboard, and in your code, the function gets triggered for both mouse and keyboard.