05-03-26

Rapid Strafe Tap Lua Script

This Lua script for Rebind hardware input allows you to rapidly strafe left and right by holding a key. Configure the tap speed with a slider. Learn how to use Run, Sleep, HID, and UI Schema in your o

rebindlua scriptstraferapid taphardware inputscriptlua

Question

Rapid tap A/D for strafing

Rebind AI

luau
-- rebind: name=Rapid Strafe Tap
-- rebind: description=Tap A/D rapidly to strafe left/right

local cfg = UI.Schema({
    enabled = UI.Toggle(true, { label = "Enable" }),
    cps = UI.Slider(10, { min = 1, max = 20, label = "Taps Per Second" }),
    hold_key = UI.Keybind("Mouse2", { label = "Hold to Strafe" }),
})

local task = nil

function OnDown(key)
    if not cfg.enabled or key ~= cfg.hold_key then
        return true
    end

    task = Run(function()
        local delay = 1000 / cfg.cps
        while Input.IsDown(cfg.hold_key) do
            HID.Press("A", 30)
            Sleep(delay / 2)
            HID.Press("D", 30)
            Sleep(delay / 2)
        end
    end)
    return false
end

function OnUp(key)
    if key == cfg.hold_key and task then
        task:Cancel()
        task = nil
    end
    return true
end

function OnBlur()
    if task and task:IsRunning() then
        task:Cancel()
        task = nil
    end
end

function OnStop()
    if task and task:IsRunning() then
        task:Cancel()
    end
end

How it works:

Hold the configured key (default Mouse2/right-click) to trigger rapid alternating taps between A and D. The script uses Run() and Sleep() to loop while the button is held, pressing each key with a 30ms hold time and spacing them evenly based on the configured CPS (clicks per second).

The cps slider controls the tap rate — higher values mean faster strafing. Each tap is split in half: sleep for delay/2 between A and D, then delay/2 again before looping.

All tasks are cancelled in OnBlur() and OnStop() to prevent key ghosting.

Learn more