05-10-26
Precision Mouse Movement Lua Script
This Lua script for hardware input slows down mouse movement when a key is held, perfect for precise pixel selection. It uses the Rebind SDK to modify mouse behavior.
Question
I need a script to slow down mouse movement when I hold a modifier key for precise pixel selection.
Rebind AI
I'll create a script that slows down mouse movement when you hold a modifier key. This is perfect for precise pixel-level selection in image editors, design tools, or any application requiring fine cursor control.
-- rebind: min_sdk=0.1.0 mouse_block=true
-- rebind: name=Precision Mouse
-- rebind: description=Hold a key to slow down mouse movement for precise selection
local cfg = UI.Schema({
hold_key = UI.Keybind("Mouse3", { label = "Precision Key", tooltip = "Hold this to activate slow mode" }),
slowdown = UI.Slider(25, {
min = 5,
max = 75,
suffix = "%",
label = "Movement Speed",
tooltip = "Lower % = slower movement"
}),
acceleration = UI.Toggle(false, {
label = "Enable Acceleration",
tooltip = "Gradually speed up longer movements"
}),
})
function OnMove(dx, dy)
if not Input.IsDown(cfg.hold_key) then
return true -- pass through normally
end
local factor = cfg.slowdown / 100
if cfg.acceleration then
-- longer movements get slightly more acceleration
local magnitude = math.sqrt(dx * dx + dy * dy)
if magnitude > 5 then
factor = factor * (1 + (magnitude - 5) * 0.02)
end
end
HID.Move(dx * factor, dy * factor)
return false -- swallow the original movement
endHow it works:
- Hold to activate — When you hold the configured key (default: Mouse3/middle-click), the script intercepts all mouse movements
- Precision scaling — Each movement is multiplied by your speed percentage (e.g., 25% means 1/4 normal speed)
- Optional acceleration — If enabled, longer swipes gradually speed up, making both small adjustments and larger sweeps feel natural
- Block original input — The original fast movement is swallowed; only the scaled version reaches your PC
Usage tips:
- Use
Mouse3(middle-click) as the precision key to keep it separate from selection buttons - Set speed to 15–30% for fine pixel work, 50–75% for general precision
- Toggle acceleration on if you want to make both tiny tweaks and larger movements without lifting the key
- In Photoshop or similar tools, hold the precision key while selecting or painting
Why mouse_block=true? This modeline directive forces the engine to validate every mouse movement, which enables the return value to block input. Without it, OnMove would fire asynchronously and blocking wouldn't work.
Learn more