rb.bind(key, fn, options)runsfnwhenkeyis pressed and takes that key, so your computer never sees it. Rebind intercepts only the keys you bind.rb.bind.remap(from, to)is the one-line key-to-key form.rb.on("down", fn)/rb.on("up", fn)see every key. Returnfalseto block a key, anything else to let it through. A script with one of these handlers captures the whole keyboard, so use them only when the logic depends on keys you cannot list up front. See Input.rb.input.is_down(key)tells you whether a key is held right now, which is how chords, holds, and layers decide what to do.
Left Ctrl + Left Alt + K (Left Control + Left Option + K on macOS)
to stop every script and release every held key and button. In hardware mode,
press it on a keyboard you attached in Peripherals. See the
kill switch.
Single-key remap
rb.bind.remap takes the key you press and the key to send in its place. Caps
Lock becomes Escape; your real Escape is untouched.
handle.enabled reports the state.
A key that sends a shortcut
A bind can send any chord.rb.hid.combo presses the keys left to right and
releases them right to left in one call, so it works directly in a callback.
The when option limits the bind to a condition; when it returns false, the
key passes through as usual. Here F1 reopens the last closed tab, but only
while a Chrome window is focused.
rb.hid. To scope a whole script to some
applications with the modeline instead, see
Per-app shortcuts.
Chords
A chord fires one action when several keys are held together. Printable keys must be held back: if J passed through at once, it would already be typed by the time K completes the chord. This script holds J and K until release, sends Escape when both are down, and types the single key on release when no chord formed.Tap or hold
One key, two jobs: tap Space for a space, hold it and press H, J, K, or L for the arrow keys. The script withholds Space until it knows which one you meant.used stops a stray space after you used the hold, and TAP_MS keeps a long,
idle hold from typing a late one. Raise TAP_MS if quick taps go missing.
Tap for a key, hold for a modifier
Tap Caps Lock for Escape; hold it and press another key for Ctrl. Aninput_down observer notes any other key pressed during the hold. Observers
see every key, bound ones included, and take no exclusive capture.
Hold-to-access layer
A layer is a hold scaled up: hold one key to turn a block of keys into something else, release it to return to normal. The mappings live in a table, so adding a key is one line.process= or window= line to the modeline.
Remap one device only
rb.bind.remap answers to every device unless its key is a
pinned key. To remap keys on one keyboard only,
use the layer pattern above with device in place of when. Give the keyboard
a nickname in Peripherals first; see
Attach your devices.
This script turns Caps Lock and Right Alt into Ctrl on a keyboard nicknamed
compact.