Skip to main content

Python wrapper for AoJia Windows automation library

Project description

AoJia Library

Python wrapper for AoJia Windows automation library.

A powerful Windows automation library providing screen capture, color/image finding, keyboard/mouse simulation, memory operations, OCR, and more.

Features

  • Window Operations: Find, move, resize, close windows
  • Keyboard Simulation: Key press, text input with random delays
  • Mouse Simulation: Move, click, drag with human-like behavior
  • Screen Capture: Capture screen regions to files
  • Color Finding: Find colors and multi-color patterns
  • Image Matching: Find images on screen with similarity matching
  • OCR: Text recognition using dictionary files
  • Memory Operations: Read/write process memory
  • Process Management: Enumerate, terminate processes
  • File Operations: Read, write, copy, move files
  • Background Mode: Send input to background windows

Requirements

  • Windows OS (64-bit)
  • Python 3.8+
  • pywin32

Installation

pip install aojialibrary

Quick Start

from aojialibrary import AoJia

# Create and initialize
aj = AoJia()
aj.initialize()

# Find a window
hwnd = aj.find_window(0, "notepad", 0, "", "", 1, 0)
print(f"Found window: {hwnd}")

# Get window info
title = aj.get_window_title(hwnd)
print(f"Window title: {title}")

# Mouse operations
aj.move_to(100, 100)
aj.left_click()

# Screen capture
aj.screen_shot(0, 0, 800, 600, "screenshot.png", 2)  # PNG format

# Find color
found, x, y = aj.find_color(0, 0, 1920, 1080, "FF0000", 0.9, 0)
if found:
    print(f"Found red at ({x}, {y})")

# Find image
found, idx, x, y = aj.find_pic(0, 0, 1920, 1080, "target.png", "000000", 0.9, 0, 0)

# Type text
aj.type_text("Hello, World!")

# Clean up
aj.release()

Context Manager

from aojialibrary import AoJia

with AoJia() as aj:
    # Move mouse and click
    aj.move_to(100, 100)
    aj.left_click()
    
    # Find and click image
    if aj.find_and_click(0, 0, 1920, 1080, "button.png", 0.9):
        print("Clicked button!")

API Reference

Initialization

from aojialibrary import AoJia, set_dll_path

# Use bundled DLL (recommended)
aj = AoJia()
aj.initialize()

# Or use custom DLL path
set_dll_path(r"C:\path\to\AoJia64.dll")
aj = AoJia(auto_register=False)
aj.initialize()

Window Operations

# Find window by criteria
hwnd = aj.find_window(
    parent=0,           # Parent window handle
    pro_name="notepad", # Process name
    pro_id=0,           # Process ID (0 for any)
    class_name="",      # Window class (empty for any)
    title="",           # Window title (empty for any)
    win_type=1,         # 0=all, 1=visible, 2=hidden
    timeout=0           # Timeout in ms
)

# Get window information
title = aj.get_window_title(hwnd)
rect = aj.get_window_rect(hwnd)  # Returns (x1, y1, x2, y2)
size = aj.get_window_size(hwnd)  # Returns (width, height)
class_name = aj.get_window_class(hwnd)

# Window operations
aj.move_window(hwnd, x, y)
aj.set_window_size(hwnd, width, height)
aj.close_window(hwnd)

# Coordinate conversion
screen_x, screen_y = aj.client_to_screen(hwnd, client_x, client_y)
client_x, client_y = aj.screen_to_client(hwnd, screen_x, screen_y)

Mouse Operations

# Basic movements
aj.move_to(x, y)           # Move to absolute position
aj.move_r(dx, dy)          # Move relative to current position

# With randomization (human-like)
aj.move_to_d(x, y, xr_min, xr_max, yr_min, yr_max, r_min, r_max, speed)

# Clicks
aj.left_click()
aj.right_click()
aj.middle_click()

# Clicks with random delay
aj.left_click_d(r_min=50, r_max=100, rd_min=100, rd_max=200)

# Drag operations
aj.left_down()
aj.move_to(x, y)
aj.left_up()

# Mouse wheel
aj.wheel_up()
aj.wheel_down()

# Get mouse position
x, y = aj.get_mouse_pos()

Keyboard Operations

# Key press (virtual key code)
aj.key_press(0x41)  # 'A' key

# Key press (string)
aj.key_press_s("a")
aj.key_press_s("enter")
aj.key_press_s("ctrl")

# Key combinations
aj.key_press_z("ctrl+c", 50, 100)  # Ctrl+C with random delay

# Text input with random delays
aj.type_text("Hello, World!", interval_min=50, interval_max=100)

# Key state
if aj.get_key_d_state(0x41):  # Check if 'A' is pressed
    print("A is pressed")

Color and Image Finding

# Get color at position
color = aj.get_color(x, y)

# Compare color
if aj.cmp_color(x, y, "FF0000", 0.9, 0):
    print("Color matches!")

# Find color in region
found, x, y = aj.find_color(
    x1=0, y1=0, x2=1920, y2=1080,
    color="FF0000",
    sim=0.9,      # Similarity (0.0-1.0)
    direction=0   # Search direction
)

# Find all color occurrences
results = aj.find_color_ex(0, 0, 1920, 1080, "FF0000", 0.9, 0)
# Returns "x1,y1|x2,y2|..."

# Find image
found, idx, x, y = aj.find_pic(
    x1=0, y1=0, x2=1920, y2=1080,
    pic_name="target.png",
    delta_color="000000",  # Color tolerance
    sim=0.9,
    direction=0,
    pic_type=0
)

# Load pictures for faster matching
aj.load_pic("image1.png|image2.png")
found, idx, x, y = aj.find_pic(0, 0, 1920, 1080, "image1.png|image2.png", "000000", 0.9, 0, 0)
aj.free_pic("")  # Free all loaded pictures

Screen Capture

# Capture screen region
aj.screen_shot(
    x1=0, y1=0, x2=800, y2=600,
    pic_name="screenshot.png",
    pic_type=2,    # 0=BMP, 1=JPG, 2=PNG
    quality=100    # For JPG (1-100)
)

OCR Text Recognition

# Load dictionary
aj.load_dict(0, "dict.txt")

# Find text
found, idx, x, y = aj.find_str(
    x1=0, y1=0, x2=1920, y2=1080,
    text="Hello",
    color="FFFFFF-000000",
    sim=0.9,
    direction=0,
    color_type=0,
    dict_type=0
)

# OCR (recognize all text in region)
text = aj.ocr(
    x1=0, y1=0, x2=800, y2=600,
    text="",
    color="FFFFFF-000000",
    sim=0.9,
    color_type=0, dict_type=0,
    ocr_type=0, type_t=0,
    h_line="",
    pic_name=""
)
print(f"Recognized: {text}")

# Free dictionary
aj.free_dict(0)

Memory Operations

# Get process ID from window
pid = aj.get_window_thread_process_id(hwnd, 0)

# Read integer
value = aj.read_int_l(pid, hwnd, address, 2, None)  # 2=dword

# Read float
value = aj.read_float_l(pid, hwnd, address)

# Read string
text = aj.read_string_l(pid, hwnd, address, 100, 0, None)  # 100 chars, ANSI

# Write integer
aj.write_int_l(pid, hwnd, address, 12345, 2)

# Find value in memory
results = aj.find_int(pid, hwnd, "0-7FFFFFFFFFFFFFFF", 100, 200, 2, 4096, 0, 1, 1, "")

Background Mode

# Enable background mode
aj.kq_hou_tai(
    hwnd=hwnd,
    screen="gdi",     # Screen capture mode
    keyboard="normal", # Keyboard mode
    mouse="normal",    # Mouse mode
    flag="",
    bg_type=0
)

# Now you can send input to background window
aj.move_to(100, 100)
aj.left_click()

# Disable background mode
aj.gb_hou_tai()

File Operations

# Read/write file
content = aj.read_file("test.txt")
aj.write_file("test.txt", "Hello")

# File management
aj.copy_file("src.txt", "dst.txt", 1)  # Overwrite
aj.move_file("old.txt", "new.txt", 1)
aj.delete_file("temp.txt")

# INI file operations
value = aj.read_ini("config.ini", "Section", "Key")
aj.write_ini("config.ini", "Section", "Key", "Value")

# Check file/folder
if aj.is_file_or_folder("path") == 1:
    print("It's a file")

Process Operations

# Get current process info
pid = aj.get_current_process_id()
tid = aj.get_current_thread_id()

# Enumerate processes
processes = aj.enum_process("notepad")  # Filter by name

# Terminate process
aj.terminate_process(pid, 0, "", 0)

# Module info
base = aj.get_module_base_addr(pid, hwnd, "kernel32.dll")
size = aj.get_module_size(pid, hwnd, "kernel32.dll")

Utility Functions

# Random numbers and strings
rand_int = aj.random(1, 100)
rand_str = aj.random_str(10, 2)  # 10 chars, alphanumeric

# Delay
aj.delay(100, 200)  # Random delay 100-200ms

# System info
version = aj.ver_s()  # Plugin version
os_info = aj.get_os()  # OS information

# Error handling
error_code = aj.get_last_error()

DLL Registration

The library includes the necessary DLL files. Registration is automatic on first use.

For manual registration:

from aojialibrary import register

# Set DLL path (recommended - no registry modification)
register.set_dll_path()

# Or register COM to system registry (requires admin)
register.register_com()

# Unregister
register.unregister_com()

License

MIT License

Credits

This library wraps the AoJia automation library for Windows.

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

aojialibrary-1.0.1.tar.gz (4.5 MB view details)

Uploaded Source

Built Distribution

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

aojialibrary-1.0.1-py3-none-any.whl (4.5 MB view details)

Uploaded Python 3

File details

Details for the file aojialibrary-1.0.1.tar.gz.

File metadata

  • Download URL: aojialibrary-1.0.1.tar.gz
  • Upload date:
  • Size: 4.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for aojialibrary-1.0.1.tar.gz
Algorithm Hash digest
SHA256 219f278c93ccb2f1d113503c15bb968de68c233327c823a78a205e9b551c6a34
MD5 28d9d0cf5ab045e5c86cc8a9ea50da84
BLAKE2b-256 25b8033b90e646e3f6d11985832a3dc6872db42f631aa44721d83e6143cb7503

See more details on using hashes here.

File details

Details for the file aojialibrary-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: aojialibrary-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for aojialibrary-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7fd7dc3b109f34e780daecece23e301035beb55f9034fb7d0a3ac76db0a80805
MD5 7f9a9c8275ee26357a1efe14e72df759
BLAKE2b-256 5e2084042e6f172a569f52581e4d12ab524f1ebe5c670b935e9334d594d8e83b

See more details on using hashes here.

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