05-05-26

Key Press Rate Limiter Lua Script

This Lua script for Rebind hardware input limits the rate at which keys can be pressed. It prevents rapid-fire spam by enforcing a minimum delay between key presses, configurable via a UI slider. Usef

rebindlua scriptkey pressrate limiterspam protectionhardware inputui

Question

Spam protection: limit how fast a key can repeat

Rebind AI

luau
-- rebind: name=Spam Protection

local cfg = UI.Schema({
    enabled = UI.Toggle(true, { label = "Enable" }),
    min_delay = UI.Slider(100, { min = 10, max = 1000, suffix = "ms", label = "Min Delay Between Presses" }),
})

local lastPress = {}

function OnDown(key)
    if not cfg.enabled then
        return true
    end

    local now = System.Time()
    local lastTime = lastPress[key] or 0

    if now - lastTime < cfg.min_delay then
        return false
    end

    lastPress[key] = now
    return true
end

function OnUp(key)
    return true
end

How it works:

This script tracks the last time each key was pressed using a table (lastPress). When a key goes down, it checks if enough time has passed since the last press. If not enough time has elapsed, it blocks the key by returning false. Otherwise, it updates the timestamp and lets the key through.

The min_delay slider lets you configure how many milliseconds must pass between consecutive presses of the same key. Set it higher for stricter rate limiting, lower for more lenient protection.

Common use cases:

  • Prevent rapid-fire spam in chat or online games
  • Rate-limit accidental double-presses
  • Enforce minimum intervals between macro executions

The script tracks each key independently, so different keys can be pressed in quick succession without interference.

Learn more