05-08-26
Drag Lock Toggle Lua Script
This Lua script for Rebind hardware input allows you to toggle a mouse drag state with a single key press. It's useful for accessibility and one-handed use, and automatically releases the drag when yo
rebindlua scriptdrag locktogglehardware inputaccessibilityscript
Question
I need a Rebind script for a drag lock feature. The script should allow me to click a button once to start dragging (mouse button down), and click it again to stop dragging (mouse button up).
Rebind AI
lua
-- rebind: min_sdk=0.1.0
-- rebind: name=Drag Lock
local cfg = UI.Schema({
enabled = UI.Toggle(true, { label = "Enable" }),
toggle_key = UI.Keybind("Mouse3", { label = "Drag Lock Key" }),
})
local dragging = false
function OnDown(key)
if not cfg.enabled or key ~= cfg.toggle_key then
return true
end
if dragging then
-- Release drag
HID.Up("Mouse1")
dragging = false
UI.Notify("Drag released", "info")
else
-- Start drag
HID.Down("Mouse1")
dragging = true
UI.Notify("Drag locked", "info")
end
return false
end
function OnBlur()
if dragging then
HID.Up("Mouse1")
dragging = false
end
end
function OnStop()
if dragging then
HID.Up("Mouse1")
end
endHow it works:
- Click the toggle key (default Mouse3) once to lock Mouse1 in the down state
- Move your mouse while dragging is locked
- Click the toggle key again to release the drag
- If you switch windows while dragging, the script automatically releases the button in
OnBlur
Customization:
- Change
toggle_keyto any key you want (e.g.,F8,LAlt,Mouse4) - Disable the feature temporarily with the
enabledtoggle
This is useful for accessibility, one-handed workflows, or situations where holding a button is difficult or inconvenient.
Learn more: