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:

01function onKeyPress(actionName, userInputState, inputObject)
02        print("R has been pressed")
03end
04 
05game.ContextActionService:BindAction("keyPress",onKeyPress, false, Enum.KeyCode.R)
06 
07runService.RenderStepped:connect(function()  -- update every 1/60 of a second
08    if [not sure what to do here] then
09        --do something
10    end
11end)

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

1local uis = game:GetService("UserInputService")
2uis.InputBegan:Connect(function(Input, IsTyping)
3 
4if Input.KeyCode == Enum.KeyCode.R and not IsTyping then
5 
6-- do stuff
7    end
8end)
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