Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rebind

Python client for the Rebind remote access WebSocket protocol. Blocking and asyncio APIs. Pure Python, works on Windows, macOS, and Linux.

Install

pip install git+https://github.com/usinput/rebind-client-py.git

Quick start

from 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:
            break

Read input state

with 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)

Screen sampling

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")

Window management

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)

Any server command

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"]

Auth

r = RebindRemote("ws://127.0.0.1:19561", token="my-secret")
r.connect()

Async

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)

Auto-reconnect

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
)

Links

About

Python client for the Rebind WebSocket protocol

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages