double click function?

So you want to check if a button is pressed twice in a row? If so, then I guess you could try something like this:


It triggers the "DoublePressed" function every time you hit spacebar twice within 100ms of the previous press.
local key = 22 -- INPUT_JUMP (SPACE)

function DoublePressed()
    print("double pressed")
end

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        
        if (IsControlJustReleased(0, key)) then
            local pressedAgain = false
            local timer = GetGameTimer()
            while true do
                Citizen.Wait(0)
                if (IsControlJustPressed(0, key)) then
                    pressedAgain = true
                    break
                end
                if (GetGameTimer() - timer >= 100) then
                    break
                end
            end
            if (pressedAgain) then
                DoublePressed()
            end
        end
    end
end)
2 Likes