Skip to main content
A Rebind script is a Luau file that registers handlers. Rebind calls them as input arrives and time passes; they can read each key press, mouse move, and scroll, block it, or send something else. This guide teaches the model and the common patterns. Exact parameters for every function are in the SDK reference. New to Rebind? Write your first script and learn the kill switch first.

Lifecycle

Register a handler with rb.on(event, fn). The events:
  • "start" and "stop": set up and tear down (start timers, stop tasks, release keys).
  • "focus" and "blur": the window you target gained or lost focus. See Limit a script to certain apps.
  • "tick": runs on a fixed cadence while the script is active, with the elapsed milliseconds. The rate and its limits are in the SDK reference.
  • "down", "up", "move", "scroll", and "axis" (controller sticks and triggers): input, covered next.
A script with no targeting is always active, so its focus and blur handlers never fire. Events lists every event and its arguments.

Input and blocking

Input handlers run when input arrives from your keyboard and mouse, or in hardware mode from a game controller. Their return value decides whether your computer sees the input:
  • return true, no return, or return nil: the input passes through.
  • return false: the input is swallowed.
That is how a remap works: block the original key, then send another one with rb.hid.
An up handler also receives how long the key was held, in milliseconds. rb.bind is the shortcut for specific keys, and it has the opposite default: it blocks the key unless you pass { swallow = false }, and it ignores the callback’s return value. For this remap, rb.bind.remap("CapsLock", "Escape") is the whole script. See rb.bind. Prefer rb.bind when you only care about specific keys. A down or up handler makes Rebind intercept every key; the SDK reference covers this and the key_block=false opt-out. The rest of this guide uses rb.bind for single keys. Mouse movement needs hardware mode; see How it Works. To change or swallow moves, add mouse_block=true to the modeline; then a move handler’s return value counts:
Keys have names such as "A", "LCtrl", and "Mouse1". Names you pass to rb ignore case, but handlers receive the exact spelling in the Key reference, so compare against that spelling: key == "CapsLock", not "capslock". The Key reference lists every name and alias.

Sending output

rb.hid sends keyboard, mouse, and (on a Rebind Link whose USB profile includes a joypad or the Xbox controller) controller output; where it goes depends on the mode. See Controllers for joypad output.
  • rb.hid.down and rb.hid.up hold and release a key across time.
  • rb.hid.combo fires a chord in one call: rb.hid.combo("LCtrl+V") presses left to right and releases right to left.
  • rb.hid.press taps a key, with an optional hold in milliseconds.
  • rb.hid.type sends a string in one call.
rb.hid.combo, rb.hid.down, and rb.hid.up return at once, so they are safe anywhere, including an input handler or an rb.bind callback. rb.hid.type needs no coroutine. rb.hid.press and rb.hid.typewriter wait between steps, so they run only inside rb.run() or an rb.async() callback. Which characters rb.hid.type can send depends on the output and the keyboard layout; see Transport key support. For a fixed delay between characters, use rb.hid.typewriter(text, delay_ms) inside a coroutine. For long or arbitrary Unicode text, set the clipboard and paste, where the platform supports it. The rest of the output surface, including mouse movement, scroll, and joypad, is in the rb.hid reference.
Held modifiers. A modifier you are physically holding applies to script output too: a key re-sent while Shift is down still carries Shift. That is right for remaps, but a macro that types text while you hold a modifier inherits it. Check rb.input.modifiers() first when output must be free of held modifiers.

Doing things over time

For sequences, delays, and loops, run the work in a coroutine and pause it with rb.sleep(). rb.async() makes a bind’s callback a coroutine:
rb.run() starts a coroutine anywhere else, and it runs alongside everything else. rb.sleep() pauses only the coroutine it is in, and works only inside one. Also useful:
  • rb.after(ms, fn): a one-off delay without writing the coroutine.
  • rb.timer.after and rb.timer.every: delayed or repeated callbacks without a loop.
Coroutines are cooperative and resume on engine ticks (8,000 a second), whatever the script’s tick_rate. rb.sleep resumes on the first engine tick past its deadline, and a coroutine body that never sleeps runs straight through in one tick. A loop with no rb.sleep stalls the script, and input with it, until the runtime stops it with script execution budget exceeded. Put an rb.sleep inside every long-running loop.
rb.run() returns a handle with stop() and is_running(). Stop long-running tasks in a stop or blur handler:
Exact signatures are under Globals and rb.timer.

Reading state

To know what is happening right now instead of waiting for an event, read it:
  • rb.input reports held keys, modifiers, and how long a key has been down. Use it in a tick handler or an rb.run() loop.
  • rb.system gives the time, the cursor position, the screen size, and the focused window.
See rb.input and rb.system. The Double-tap pattern below uses rb.system.time.

Config panels

A script can define settings that appear in its Options tab, so people can tune it without editing code. rb.ui.schema declares the controls; read and write values through the handle it returns. Values persist for that script, and the panel is available before the script runs:
A script's Options tab with an Auto-start toggle and controls grouped under headings: a keybind, toggles, a select, and sliders

A script's Options tab, built from its rb.ui.schema call. Changes apply while it runs. Sample data.

The widgets (toggles, sliders, keybinds, selects, text, colors, lists of strings, buttons, dividers) and notifications are in the rb.ui reference.

Splitting across files (require)

As a script grows, move shared code into its own file and load it with require(). A module is a .luau or .lua file that returns a value, usually a table:
require resolves relative to the script’s own folder, and dots are path separators. Every rule is in the require reference.

Macros

rb.macro.play replays a recorded input sequence: a table of move, down, up, press, type, scroll, and sleep actions. Use a macro for a fixed sequence and rb.hid calls when the output depends on logic. rb.math transforms a sequence before playback. See the rb.macro reference.

Limit a script to certain apps

Limit a script to specific apps with modeline targeting. window= matches a case-insensitive substring of the focused window’s title (so window=code also matches “Visual Studio Code”); process= matches the process name the same way. Repeat either key on one line or across lines. Positive rules combine with OR:
Use window_regex= and process_regex= when one expression is clearer than several literals. They ignore case and use Rust regex syntax, so lookaround and backreferences are not supported:
Exclusions deactivate a script when they match, and they win over positive rules. With only exclusions, a script is active everywhere except there:
A start handler runs when a targeted script loads. While its target does not match, its input handlers, timers, coroutines, and tick handler stay inactive. Use untargeted scripts for system-wide behavior such as remaps and media keys. An invalid or empty regular expression stops a script from loading instead of widening its scope. When several scripts run, z_index decides which sees input first (a false return blocks the ones below), and instance decides what happens when a script starts while a copy is running. platforms names the operating systems a script supports. Every key is in the Modeline reference.

Permissions

A script lists what it needs, such as exec or net, with permission= in its modeline. With no permission line it holds every permission except observe, which a script must list to record your input, what Rebind sends, your screen and the names of its controls. The tokens are in the permissions reference; how Rebind asks you before a script from someone else runs is in Permissions.

Patterns

Toggle

Double-tap

Style

The conventions every example in these docs follows:
  • Indent with 2 spaces. Never tabs, never 4.
  • Naming: SDK names are snake_case (rb.hid.press, rb.input.is_down), and so are your locals and local functions (dwell_start, local function set_virt). Module-level constants are UPPER_SNAKE. The UI config table is conventionally named cfg.
  • local everything. Register handlers with rb.on and declare everything else local, including functions.
  • Double-quoted strings. Use [[ ]] long strings for regex patterns and multi-line text.
  • Stay flat: return early. Guard and return rather than nesting; use a and b or c for a ternary.
  • Types are optional. Luau is typed; annotate where it clarifies (local count: number = 0), not the obvious.
  • Comments explain why, not what, and stay sparse and lowercase. Use -- for a single line and one --[[ ]] block instead of several -- lines.
  • Keep lines to about 80 characters, with spaces after commas and around operators and one statement per line.

Validation

When a script loads, Rebind writes warnings to its Logs tab without stopping it:
  • No handlers: a script with no rb.on handler and no rb.bind logs “no event handlers or binds defined”. A script driven only by rb.timer or a server such as rb.net.listen gets this warning too and still runs.
  • HTTP in a fast tick: a tick handler with a tick_rate above 1000 and rb.net.get or rb.net.post anywhere in the source logs a warning. HTTP client calls belong in rb.run(), where they yield.
Run rebind check to validate a script or package before you run it.

Type checking

The editor in the app has Rebind SDK autocomplete and hover help. For VS Code or another editor, follow Editor setup to load the same rebind.d.luau definitions into the Luau Language Server.