Skip to main content

Windows macro input API — keyboard, mouse, window & pixel

Project description

urmacropkg

Windows macro input API — keyboard, mouse, window & pixel operations.

Uses SendInput / win32 for real input events compatible with games (DirectInput, raw input, anti-cheat).

Install

pip install urmacropkg

With OCR support (Windows native):

pip install urmacropkg[ocr]

Usage

from urmacro import *

# Keyboard
press('a')
press('ctrl', hold=True)
press('c')
release('ctrl')
write("hello world")

# Mouse
left_click()
smooth_move(960, 540, duration=0.5)
send_input_delta(100, 0)   # raw relative move (game cameras)

# Window
focus_window("Notepad")
focus_window("MyGame", full_scale=True)

# Pixel
color = get_pixel_color(100, 200)
if check_pixel_color(500, 300, r=255, g=0, b=0, tolerance=15):
    print("red pixel found")

pos = find_color(0, 0, 1920, 1080, r=0, g=255, b=0)

# Interruptible sleep (for macro loops)
def my_macro(get_active_status):
    while get_active_status():
        press('space')
        if not sleep_interruptible(1.0, get_active_status):
            return

API Reference

Keyboard

Function Description
press(key) Press and release a key ('a', 'f1', 'enter', 'space', '\\'...)
press(key, hold=True) Hold a key down
release(key) Release a held key
release_all() Release all held keys and mouse buttons
write(text, delay=0.05) Type a string (Unicode, supports accents)

Mouse

Function Description
left_click() / right_click() Click
left_click(hold=True) Hold mouse button
release_left_click() / release_right_click() Release held button
move(x, y) Instant cursor warp (cosmetic)
send_input_move(x, y) Absolute move via SendInput (UI clicks)
send_input_delta(dx, dy) Relative move via SendInput (game cameras)
smooth_move(x, y, duration=0.4) Smooth Bezier move via SendInput
smooth_move(dx, dy, relative=True) Smooth relative move

Window

Function Description
find_window(title, partial=True) Returns (hwnd, title) or (None, None)
focus_window(title, partial=True, full_scale=False) Bring window to foreground

Pixel & Screen

Function Description
get_pixel_color(x, y) Returns (R, G, B) or None
check_pixel_color(x, y, r, g, b, tolerance=10) Color match with tolerance
find_color(x, y, w, h, r, g, b, tolerance=10) Find first pixel of color in region
find_color_bounds(x, y, w, h, ref_x, ref_y) Bounding box of a color zone
screenshot_region(x, y, w, h) PIL Image of a screen region
read_text(x, y, w, h, lang='fr') OCR via Windows native API (requires [ocr])
get_cursor_pos() Returns (x, y)
get_screen_size() Returns (width, height)
get_zone_center(x1, y1, x2, y2) Returns (cx, cy)

Timing

Function Description
sleep_interruptible(seconds, get_active_status) Sleep that returns False if macro is stopped

All pixel functions accept an optional window_title argument — coordinates are then relative to the window's client area.

Requirements

  • Windows 10/11
  • Python 3.10+
  • pywin32
  • Pillow
  • winocr (optional, for OCR)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

urmacropkg-1.0.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

urmacropkg-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file urmacropkg-1.0.0.tar.gz.

File metadata

  • Download URL: urmacropkg-1.0.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for urmacropkg-1.0.0.tar.gz
Algorithm Hash digest
SHA256 be5bf982d1f381ef5442642e009b5222646ef009a29b236b7823e6c452d749f6
MD5 053972ee5e6d3f2ade155b8077ab1657
BLAKE2b-256 03df095b0521d8f39fc24c25f1ea6a9d0fc69800bc3487e85178707dffbfbc97

See more details on using hashes here.

Provenance

The following attestation bundles were made for urmacropkg-1.0.0.tar.gz:

Publisher: publish.yml on Yxoo/urmacropkg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file urmacropkg-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: urmacropkg-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for urmacropkg-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ea969754d4482e2fb2fb4a5a912f73cbedac555222f5856215a2c8f4b9a2a2f
MD5 a3820da38f47f1b7bd26bc023d545698
BLAKE2b-256 be11ca4d06e8764a4a2c60bca04a9aca79c7a49689db62bd6ce21d465c6aed39

See more details on using hashes here.

Provenance

The following attestation bundles were made for urmacropkg-1.0.0-py3-none-any.whl:

Publisher: publish.yml on Yxoo/urmacropkg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page