05-03-26
Anti-AFK Movement Randomizer Script
This Lua script for Rebind hardware input randomizes movement patterns to prevent AFK detection. It offers WASD, mouse, and mixed movement options with customizable intervals and durations.
rebindlua scriptanti-afkmovementrandomizerhardware inputscript
Question
Anti-AFK movement randomizer
Rebind AI
luau
-- rebind: min_sdk=0.1.0
-- rebind: name=Anti-AFK Movement Randomizer
-- rebind: description=Randomize movement patterns to avoid AFK detection
local cfg = UI.Schema({
enabled = UI.Toggle(true, { label = "Enable Anti-AFK" }),
toggle_key = UI.Keybind("F8", { label = "Toggle Key" }),
interval_min = UI.Slider(10, { min = 5, max = 60, label = "Min Interval", suffix = "s", group = "Timing" }),
interval_max = UI.Slider(30, { min = 10, max = 120, label = "Max Interval", suffix = "s", group = "Timing" }),
movement_type = UI.Select("Mixed", { "Wasd", "Mouse", "Mixed" }, { label = "Movement Type", group = "Behavior" }),
movement_duration = UI.Slider(2000, { min = 500, max = 5000, label = "Duration", suffix = "ms", group = "Behavior" }),
mouse_distance = UI.Slider(50, { min = 10, max = 200, label = "Mouse Distance", suffix = "px", group = "Mouse" }),
mouse_speed = UI.Slider(100, { min = 25, max = 400, label = "Mouse Speed", suffix = "ms/px", group = "Mouse" }),
randomize_keys = UI.Toggle(true, { label = "Randomize WASD", group = "Keyboard" }),
key_hold_time = UI.Slider(500, { min = 100, max = 2000, label = "Key Hold Time", suffix = "ms", group = "Keyboard" }),
also_mouse_move = UI.Toggle(false, { label = "Also Move Mouse", group = "Keyboard", showIf = "randomize_keys" }),
jitter = UI.Slider(0, { min = 0, max = 50, label = "Add Jitter", suffix = "%" }),
})
local active = false
local currentTask = nil
local function randomKey()
local keys = { "W", "A", "S", "D" }
return keys[Math.Random(1, #keys)]
end
local function applyJitter(value)
if cfg.jitter == 0 then return value end
local jitterAmount = value * (cfg.jitter / 100)
return value + Math.Random(-jitterAmount, jitterAmount)
end
local function performWasdMovement()
local key = randomKey()
local holdTime = applyJitter(cfg.key_hold_time)
HID.Down(key)
Sleep(holdTime)
HID.Up(key)
if cfg.also_mouse_move then
Sleep(100)
local dx = Math.Random(-20, 20)
local dy = Math.Random(-20, 20)
HID.Move(dx, dy)
end
end
local function performMouseMovement()
local angle = Math.Random(0, 360)
local radians = angle * (math.pi / 180)
local distance = applyJitter(cfg.mouse_distance)
local dx = math.cos(radians) * distance
local dy = math.sin(radians) * distance
local steps = 10
local stepX = dx / steps
local stepY = dy / steps
local stepDelay = cfg.mouse_speed / steps
for i = 1, steps do
HID.Move(stepX, stepY)
Sleep(stepDelay)
end
end
local function performMixedMovement()
if Math.Random(1, 2) == 1 then
performWasdMovement()
else
performMouseMovement()
end
end
local function startAntiAfk()
currentTask = Run(function()
while active do
local delay = Math.Random(cfg.interval_min * 1000, cfg.interval_max * 1000)
Sleep(delay)
if not active then break end
if cfg.movement_type == "Wasd" then
performWasdMovement()
elseif cfg.movement_type == "Mouse" then
performMouseMovement()
else
performMixedMovement()
end
Sleep(cfg.movement_duration)
end
end)
end
function OnStart()
Log.Info("Anti-AFK initialized. Press " .. cfg.toggle_key .. " to toggle.")
end
function OnDown(key)
if key == cfg.toggle_key then
cfg.enabled = not cfg.enabled
if cfg.enabled then
active = true
startAntiAfk()
UI.Notify("Anti-AFK enabled", "success")
else
active = false
if currentTask and currentTask:IsRunning() then
currentTask:Cancel()
end
UI.Notify("Anti-AFK disabled", "info")
end
return false
end
return true
end
function OnStop()
active = false
if currentTask and currentTask:IsRunning() then
currentTask:Cancel()
end
end
function OnBlur()
active = false
if currentTask and currentTask:IsRunning() then
currentTask:Cancel()
end
UI.Notify("Anti-AFK paused", "warning")
end
function OnFocus()
if cfg.enabled then
active = true
startAntiAfk()
UI.Notify("Anti-AFK resumed", "info")
end
endHow It Works
This script automatically performs randomized movement patterns to prevent AFK detection in games or applications. Key features:
Movement Types:
- WASD – Randomly presses W, A, S, or D for a configurable duration
- Mouse – Moves the cursor in a random direction by a random distance
- Mixed – Alternates randomly between WASD and mouse movement
Randomization:
- Interval between movements varies between
interval_minandinterval_max - Each movement duration can be randomized with jitter
- Mouse movement direction and distance are randomized
- WASD selection is random each cycle
Advanced Options:
- Enable mouse movement even during WASD patterns (
also_mouse_move) - Add jitter percentage to vary hold times and distances
- Control mouse movement speed (pixels per millisecond)
- Customize key hold times and movement duration
The script respects window focus — it pauses during OnBlur and resumes when you return to the window. Press the toggle key to manually enable/disable at any time.