Skip to main content
These recipes connect a Rebind script to the world outside the keyboard: other programs, what is on screen, and the clock. For a ready-made WebSocket server with client libraries, use Remote Control instead of writing your own.

A WebSocket remote

rb.net.ws_listen serves a script over WebSocket, so another program can send it commands and receive pushed messages. This script accepts JSON commands to type text and move the mouse, and answers each request that carries an id.
Connect from Python with the websocket-client package:
Notes:
  • rb.net.ws_listen needs the net permission. Without the host option it listens on every network interface, which lets other computers connect.
  • This script has no authentication. Any program on the computer can connect, including a web page open in a browser. Add a token check before you let it do anything you would not let every local program do.
  • Incoming messages are dispatched in batches each tick; the per-tick limits are under Limits.

An HTTP trigger

rb.net.listen serves HTTP on 127.0.0.1 unless it is given a host, so a shell script, a Stream Deck action, or a cron job on this computer can trigger a key press with one request. The handler answers at once and hands the press to rb.run, because a handler cannot wait.
An uncaught error in the handler stops the script, which is why parsing goes through pcall. The server has no authentication, so any program on the computer can trigger it. See rb.net.listen for the request and response fields.

A screen-condition trigger

rb.screen.pixel_hex reads one pixel. Polled on a timer, it turns a visual state into a trigger: this script watches a status indicator and presses F5 once when it turns red, then waits for it to clear. On macOS, pixel reads need Screen capture turned on (see Platforms).
When the indicator can move, search a region with rb.screen.search_color instead of reading one point. When it is an icon rather than a flat color, save a PNG of it next to the script and search for it with rb.screen.find_image, which always waits, so it runs inside rb.run. Region limits, coordinates, and the options of each call are in the screen reference. To find something you can describe but cannot capture as a color or an image, see AI recipes.

A timer-driven task

rb.timer.every runs a callback on an interval without blocking input. This script nudges the cursor one pixel and back every few minutes while it is switched on, for a long unattended job on a computer that would otherwise go idle.
The interval is read when the nudge is switched on. A timer callback is not a coroutine, so the callback starts one with rb.run to pause between the two moves. Timers end when the script stops.

A sidecar over shared memory

Keep perception and decisions in your own process, with your own model and stack, and hand each decision to Rebind over rb.pipe, a shared-memory channel for a process on the same computer. rb.pipe is Windows only; elsewhere, use the WebSocket recipe above. Opening a pipe needs the exec permission; see Permissions.
The other process maps the same region. The script reads from the second half of it; each half starts with an 8-byte sequence number and a 4-byte length, followed by the payload. The full layout is the rb.pipe wire protocol. In Python: