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

Is there any holding key event?

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.

1 comment

0

Yes its a method in User Input Service called 'IsKeyDown'. Its usage is UIS:IsKeyDown(Enum.KeyCode.[keyHere])

1 answer

✓ Accepted answer

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.

1 comment

0

Okay but I didnt understand what is tick()?

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