05-03-26

SOCD Cleaner with Humanized Overlap

This Lua script provides last-input-wins SOCD cleaning with a humanized overlap delay for hardware input, configurable via the Rebind UI. It targets specific WASD-based games.

rebindlua scriptsocdinputhardware inputoverlapscript

Question

Please write an SOCD script with humanized overlap that is configurable in the interface and only triggers on specific games that support WASD.

Rebind AI

luau
-- rebind: min_sdk=0.1.0
-- rebind: name=SOCD Cleaner
-- rebind: description=Last-input-wins SOCD with humanized overlap delay (game-specific)

local cfg = UI.Schema({
    enabled = UI.Toggle(true, { label = "Enable SOCD", group = "General" }),
    
    overlap_min = UI.Slider(15, {
        min = 0,
        max = 60,
        label = "Overlap Min",
        suffix = "ms",
        tooltip = "Minimum delay before releasing opposite key",
        group = "Overlap Timing",
    }),
    
    overlap_max = UI.Slider(35, {
        min = 0,
        max = 100,
        label = "Overlap Max",
        suffix = "ms",
        tooltip = "Maximum delay before releasing opposite key",
        group = "Overlap Timing",
    }),
    
    horizontal = UI.Toggle(true, { label = "A/D", group = "Axes" }),
    vertical = UI.Toggle(true, { label = "W/S", group = "Axes" }),
})

-- Games that support WASD movement
local SUPPORTED_GAMES = [[
    cs2|counter-strike 2|
    valorant|
    apex legends|
    escape from tarkov|
    squad|
    rust|
    garry's mod|
    half-life|
    left 4 dead|
    team fortress|
    dota|
    counter-strike|
    paladins|
    overwatch|
    call of duty|
    battlefield|
    arma
]]

local function isGameSupported()
    local win = System.Window()
    return Regex.IsMatch(win.process, SUPPORTED_GAMES)
end

-- State tracking
local held = {}           -- Which keys are physically pressed
local virt = {}           -- Which keys are virtually sent
local lastH = nil         -- Last horizontal key pressed (A or D)
local lastV = nil         -- Last vertical key pressed (W or S)
local pendingTimer = nil  -- Timer waiting to release opposite key

local function setVirt(key, on)
    if virt[key] == on then return end
    if on then
        HID.Down(key)
    else
        HID.Up(key)
    end
    virt[key] = on
end

local function cancelPending()
    if pendingTimer and pendingTimer:IsRunning() then
        pendingTimer:Cancel()
        pendingTimer = nil
    end
end

-- Resolve A/D conflict
local function resolveHorizontal()
    if not cfg.horizontal then return end
    
    cancelPending()
    
    if held["A"] and held["D"] then
        -- Both pressed: hold last-input-wins, release the other after overlap delay
        setVirt(lastH, true)
        local otherKey = lastH == "A" and "D" or "A"
        
        local delayMs = Math.Random(cfg.overlap_min, math.max(cfg.overlap_min, cfg.overlap_max))
        if delayMs > 0 then
            pendingTimer = Timer.After(delayMs, function()
                if held["A"] and held["D"] then
                    setVirt(otherKey, false)
                end
            end)
        else
            setVirt(otherKey, false)
        end
    else
        -- One or neither pressed
        setVirt("A", held["A"] or false)
        setVirt("D", held["D"] or false)
    end
end

-- Resolve W/S conflict
local function resolveVertical()
    if not cfg.vertical then return end
    
    cancelPending()
    
    if held["W"] and held["S"] then
        -- Both pressed: hold last-input-wins, release the other after overlap delay
        setVirt(lastV, true)
        local otherKey = lastV == "W" and "S" or "W"
        
        local delayMs = Math.Random(cfg.overlap_min, math.max(cfg.overlap_min, cfg.overlap_max))
        if delayMs > 0 then
            pendingTimer = Timer.After(delayMs, function()
                if held["W"] and held["S"] then
                    setVirt(otherKey, false)
                end
            end)
        else
            setVirt(otherKey, false)
        end
    else
        -- One or neither pressed
        setVirt("W", held["W"] or false)
        setVirt("S", held["S"] or false)
    end
end

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

    if key == "A" or key == "D" then
        held[key] = true
        lastH = key
        resolveHorizontal()
        return false
    end

    if key == "W" or key == "S" then
        held[key] = true
        lastV = key
        resolveVertical()
        return false
    end

    return true
end

function OnUp(key)
    if not cfg.enabled or not isGameSupported() then
        return true
    end

    if key == "A" or key == "D" then
        held[key] = false
        resolveHorizontal()
        return false
    end

    if key == "W" or key == "S" then
        held[key] = false
        resolveVertical()
        return false
    end

    return true
end

function OnBlur()
    -- Clean up all state when leaving game
    cancelPending()
    for key, _ in pairs(virt) do
        setVirt(key, false)
    end
    held = {}
    virt = {}
    lastH = nil
    lastV = nil
end

function OnStop()
    -- Clean up on script unload
    cancelPending()
    for key, _ in pairs(virt) do
        setVirt(key, false)
    end
end

How It Works

This script implements last-input-wins SOCD (Simultaneous Opposite Cardinal Directions) cleaning:

  1. Detection: Monitors A/D (horizontal) and W/S (vertical) key presses
  2. Conflict Resolution: When opposite keys are held simultaneously:
    • Sends the most recently pressed key (lastH or lastV)
    • Suppresses the opposite key initially
    • After a humanized delay (randomized between overlap_min and overlap_max), releases the suppressed key if both are still held
  3. Game Targeting: Only activates in supported WASD-based games (CS2, Valorant, Apex, etc.)
  4. Configurable: Users adjust overlap timing and can disable H/A or W/S independently via the UI
  5. Clean Cleanup: Releases all held keys and cancels pending timers when leaving the game or when the script stops

The randomized delay creates humanized input that looks natural rather than perfectly timed, preventing anti-cheat detection concerns.

Learn more: