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

How do I make a keypress listener? [Solved]

Asked by
SteamG00B 1633 Moderation Voter
6 years ago
Edited 6 years ago

I am having a bit of difficulty with checking for keypresses, I have some code that is supposed to check for a keypress every tick, but I am not sure how to check for the actual keypress:

function onKeyPress(actionName, userInputState, inputObject)
        print("R has been pressed")
end

game.ContextActionService:BindAction("keyPress",onKeyPress, false, Enum.KeyCode.R)

runService.RenderStepped:connect(function()  -- update every 1/60 of a second
    if [not sure what to do here] then
        --do something
    end
end)

Also a mini question here, is there any way to program everything instead of using small scripts everywhere?

1 answer

Log in to vote
1
Answered by 6 years ago

no need for while true do do this

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(Input, IsTyping)

if Input.KeyCode == Enum.KeyCode.R and not IsTyping then

-- do stuff
    end
end)
0
Can you explain the "IsTyping" part? SteamG00B 1633 — 6y
0
It is the second parameter given when InputBegan is fired. It indicates if player input was caused due to them interacting with UI. The common parameter name is 'gameProcessed' and is not only for checking if a player is typing in chat. xPolarium 1388 — 6y
0
So forgot to ask one last thing, how will this know who is typing? SteamG00B 1633 — 6y
0
Never mind, ignore that, I was just being stupid and didn't realize this was supposed to be in playerscripts SteamG00B 1633 — 6y
Ad

Answer this question