Opress Documentation

Three functions. Infinite automation possibilities.

click(image(...))
Click anything you see
find(text(...))
Find any text on screen
write("...")
Type like a human

Installation

Install Opress via pip:

# Install from PyPI
pip install opress

System Dependencies

macOS

# Only needed for OCR features
brew install tesseract

Linux (Ubuntu/Debian)

# Basic dependencies
sudo apt-get update
sudo apt-get install -y python3-tk scrot xclip

# OCR support
sudo apt-get install -y tesseract-ocr

Getting Started

Basic automation example:

import opress

# Take a screenshot
screenshot = opress.capture_screen()

# Find an image on screen
button_pos = opress.image_search("button.png")
if button_pos:
    # Click the found button
    opress.click(button_pos)
    
    # Type some text
    opress.write("Hello, World!")
    
    # Press Enter
    opress.press("enter")

Image Recognition

Find images on screen with OpenCV-powered template matching:

image_search(
    needle_img,
    haystack_img=None,
    search_region=None,
    confidence=0.8,
    match_method=None,
    mask=None,
    wait_time=None,
    grayscale_search=False,
    debug=False
)

Parameters:

  • needle_img: Image to find (path or image data)
  • confidence: Match threshold (0.0-1.0, default 0.8)
  • search_region: Optional region to limit search
  • grayscale_search: Use grayscale for faster matching
  • debug: Enable debugging output

Example:

# Basic search
button_pos = opress.image_search("login_button.png")

# Search with lower confidence
button_pos = opress.image_search("button.png", confidence=0.7)

# Search in specific region
region = {"top": 100, "left": 100, "width": 300, "height": 200}
button_pos = opress.image_search("button.png", search_region=region)

Text Recognition (OCR)

Find text on screen using Tesseract OCR:

text(
    needle,
    haystack=None,
    region=None,
    debug=False,
    color_inversion=False,
    foreground_color=None,
    color_threshold=100,
    binary_threshold=0,
    erosion_kernel_size=0,
    dilation_kernel_size=0,
    blur_amount=0,
    grayscale_level=0,
    wait_time=None
)

Key Parameters:

  • needle: Text string to find
  • color_inversion: Invert colors for better OCR
  • binary_threshold: Threshold for image binarization
  • erosion/dilation_kernel_size: Morphological operations

Example:

# Basic text search
submit_pos = opress.text("Submit")

# Enhanced OCR with preprocessing
text_pos = opress.text("Login", 
                      color_inversion=True,
                      binary_threshold=128,
                      debug=True)

Pixel Detection

Find pixels by RGB color values:

pixel_search(
    color,
    haystack_img=None,
    wait_time=None,
    search_region=None
)

Example:

# Find red pixel
red_pixel = opress.pixel_search((255, 0, 0))

# Find blue pixel in region
region = {"top": 0, "left": 0, "width": 500, "height": 300}
blue_pixel = opress.pixel_search((0, 0, 255), search_region=region)

Mouse & Keyboard Control

Mouse Functions

# Click at coordinates
opress.click((100, 200))

# Right-click
opress.right_click((100, 200))

# Double-click
opress.click((100, 200), clicks=2)

# Slow click (human-like)
opress.click((100, 200), slow=True)

Keyboard Functions

# Type text instantly
opress.write("Hello, World!")

# Type slowly (human-like)
opress.write_slowly("Hello, World!")

# Press keys
opress.press("enter")
opress.press("tab")
opress.press("ctrl+c")

Screen Capture

# Capture full screen
screenshot = opress.capture_screen()

# Capture specific region
region = {"top": 100, "left": 100, "width": 300, "height": 200}
region_screenshot = opress.capture_screen(region)

# Display captured frame
opress.show_captured_frame(screenshot, "My Screenshot")

Assertions & Verification

Verify conditions during automation:

# Assert image exists (raises error if not found)
opress.assert_image_exists(lambda: opress.image_search("button.png"))

# Assert text exists
opress.assert_text_exists(lambda: opress.text("Submit"))

# Verify without raising errors
if opress.verify_find(lambda: opress.image_search("button.png")):
    print("Button found!")
else:
    print("Button not found.")

Common Issues

Permission Issues

On macOS, grant Screen Recording and Accessibility permissions:

  • System Preferences → Security & Privacy → Privacy → Screen Recording
  • System Preferences → Security & Privacy → Privacy → Accessibility

Image Not Found

# Try lower confidence
image_search("button.png", confidence=0.7)

# Use debug mode
image_search("button.png", debug=True)

# Try grayscale search
image_search("button.png", grayscale_search=True)

Text Recognition Issues

# Enhance OCR with preprocessing
text("Submit", 
     color_inversion=True,
     binary_threshold=128,
     erosion_kernel_size=1)