Lifecycle
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.
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, orreturn nil: the input passes through.return false: the input is swallowed.
rb.hid.
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:
"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.downandrb.hid.uphold and release a key across time.rb.hid.combofires a chord in one call:rb.hid.combo("LCtrl+V")presses left to right and releases right to left.rb.hid.presstaps a key, with an optional hold in milliseconds.rb.hid.typesends 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 withrb.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.afterandrb.timer.every: delayed or repeated callbacks without a loop.
Coroutines are cooperative and resume on engine ticks (8,000 a second), whatever the script’stick_rate.rb.sleepresumes on the first engine tick past its deadline, and a coroutine body that never sleeps runs straight through in one tick. A loop with norb.sleepstalls the script, and input with it, until the runtime stops it withscript execution budget exceeded. Put anrb.sleepinside every long-running loop.
rb.run() returns a handle with stop() and is_running(). Stop long-running
tasks in a stop or blur handler:
rb.timer.
Reading state
To know what is happening right now instead of waiting for an event, read it:rb.inputreports held keys, modifiers, and how long a key has been down. Use it in atickhandler or anrb.run()loop.rb.systemgives the time, the cursor position, the screen size, and the focused window.
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, built from its rb.ui.schema call. Changes apply while it runs. Sample data.
rb.ui reference.
Splitting across files (require)
As a script grows, move shared code into its own file and load it withrequire(). 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:
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:
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 asexec 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 areUPPER_SNAKE. The UI config table is conventionally namedcfg. localeverything. Register handlers withrb.onand declare everything elselocal, including functions.- Double-quoted strings. Use
[[ ]]long strings for regex patterns and multi-line text. - Stay flat: return early. Guard and
returnrather than nesting; usea and b or cfor 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.onhandler and norb.bindlogs “no event handlers or binds defined”. A script driven only byrb.timeror a server such asrb.net.listengets this warning too and still runs. - HTTP in a fast tick: a
tickhandler with atick_rateabove 1000 andrb.net.getorrb.net.postanywhere in the source logs a warning. HTTP client calls belong inrb.run(), where they yield.
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 samerebind.d.luau definitions into the Luau Language Server.