I know there are events for a key pressed but is there any event that we can use to know that the player hold a key for ****X amount of seconds
For example in jailbreak for arresting players
Thanks.
I know there are events for a key pressed but is there any event that we can use to know that the player hold a key for ****X amount of seconds
For example in jailbreak for arresting players
Thanks.
The InputObject contains a changed event inherited from instance. This means that it is possible to detect when a key is released within the InputBegan event.
Example:-
local userInpService = game:GetService("UserInputService")
userInpService.InputBegan:Connect(function(inpObj, gp)
local tm = tick() -- current time
-- wait until the event has changed
-- this is the same as InputEnd firing
inpObj.Changed:Wait()
-- print time held
print("input", inpObj.UserInputType, "for key", inpObj.KeyCode, "lasted", tick() - tm)
end)
As SinisterMemories has said there are functions in the UserInputService to check if a key is currently being pressed down.
Hope this helps.
Okay but I didnt understand what is tick()?
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Yes its a method in User Input Service called 'IsKeyDown'. Its usage is UIS:IsKeyDown(Enum.KeyCode.[keyHere])