Python client for the Rebind remote access WebSocket protocol. Blocking and asyncio APIs. Pure Python, works on Windows, macOS, and Linux.
pip install git+https://github.com/usinput/rebind-client-py.gitfrom rebind import RebindRemote
with RebindRemote("ws://127.0.0.1:19561") as r:
r.hid_move(30, -5)
r.hid_press("Mouse1", hold_ms=20)
r.hid_type("hello\n")
x, y = r.system_mouse()
pixel = r.screen_pixel(x, y)
print(f"pixel at {x},{y} = rgb({pixel.r},{pixel.g},{pixel.b})")
for pos in r.mouse_events():
print(pos.x, pos.y)
if pos.x > 500:
breakwith RebindRemote("ws://127.0.0.1:19561") as r:
# poll whether a key is held
if r.input_is_down("LShift"):
print("shift is held")
# get all currently pressed keys
keys = r.input_keys()
mods = r.input_modifiers()
print(keys, mods.ctrl, mods.shift)with RebindRemote("ws://127.0.0.1:19561") as r:
res = r.screen_resolution()
# sample center pixel
px = r.screen_pixel(res.width // 2, res.height // 2)
# react to a specific on-screen color (e.g. a UI state in a QA test)
if px.r > 200 and px.g < 50 and px.b < 50:
r.hid_press("Mouse1")with RebindRemote("ws://127.0.0.1:19561") as r:
handle = r.window_find("Counter-Strike 2")
if handle:
r.window_activate(handle)
r.window_move(handle, x=0, y=0, width=1920, height=1080)Commands without a typed method are reachable through call, which returns
the reply without its id:
with RebindRemote("ws://127.0.0.1:19561") as r:
digest = r.call("hash.sha256", {"data": "hello"})["digest"]
handle = r.call("window.get_foreground")["handle"]r = RebindRemote("ws://127.0.0.1:19561", token="my-secret")
r.connect()from rebind import AsyncRebindRemote
async def main():
async with AsyncRebindRemote("ws://127.0.0.1:19561") as r:
x, y = await r.system_mouse()
# read screen and move relative to cursor
px = await r.screen_pixel(x, y)
if px.r > 200:
r.hid_move(0, -10)
# subscribe to mouse position stream
async for pos in r.mouse_events():
print(pos.x, pos.y)Enabled by default. Configure or disable via constructor options:
r = RebindRemote(
"ws://127.0.0.1:19561",
auto_reconnect=True,
reconnect_delay_ms=100,
reconnect_max_delay_ms=10000,
reconnect_max_attempts=None, # None = infinite
)- GitHub: usinput/rebind-client-py
- Docs: docs.rebind.gg