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

How to check if a player pressed a key and is NOT TYPING?

I have a script that runs an event when the letter R is pressed. The only problem is, it also runs when the player is typing and press R. Is there anyway to fix this?

This is the script:

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then 
        print("test (r)")
    end 
end)

2 comments

0

I'd like to explain what the gameProcessedEvent is. It's a boolean that is true if the input is being processed elsewhere by the game. This can be in a custom TextBox, and even, chatting.

0

sharksie described it as such : "GameProcessedEvent tells you if roblox processed the event before it told you about it. A is the jump button, R2 is the click button, and R1/L1 are the tool switch buttons. You can tell roblox to stop processing the A button by unbinding the control from ContextActionService (you can find the control in the StarterCharacterScripts). You can stop roblox from proces"

1 answer

✓ Accepted answer

Well since you already know the existence of the GameProcessedEvent, you can use that that see if they are typing with the line :

if GameProcessedEvent then return end

Ex:

game:GetService("UserInputService").InputBegan:connect(function(io,gpe)
	if gpe then return end
	if io.KeyCode == Enum.KeyCode.R then 
		print("test (r)")
	end 
end)

Addition: what a game processed event really is

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