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

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

Asked by
zValerian 108
5 years ago

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)
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. User#19524 175 — 5y
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" theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

Ad

Answer this question