Skip to main content

Collection of functions to control a Windows or Linux pc.

Project description

ControlHub python package

Read this page in Russian / Читать на русском

ControlHub is a Python automation library for Windows that provides simple APIs to control the desktop, simulate keyboard and mouse actions, and perform web-related tasks.

Installation

Install the library via pip:

pip install controlhub

Features

  • Open files and run programs
  • Simulate mouse clicks, movements, and drags
  • Simulate keyboard input and key combinations
  • Download files from the web
  • Open URLs in the default browser

API Reference & Usage Examples

controlhub.desktop

open_file(path: str) -> None

Open a file with the default application.

from controlhub import open_file

open_file("C:\\Users\\User\\Documents\\file.txt")
open_file("example.pdf")
open_file("image.png")

cmd(command: str) -> None

Execute a shell command asynchronously.

from controlhub import cmd

cmd("notepad.exe")
cmd("dir")
cmd("echo Hello World")

run_program(program_name: str) -> None

Search for a program by name and run it.

from controlhub import run_program

run_program("notepad")
run_program("chrome")
run_program("word")

fullscreen(absolute: bool = False) -> None

Maximize the current window. If absolute=True, toggle fullscreen mode (F11).

from controlhub import fullscreen

fullscreen()
fullscreen(absolute=True)
fullscreen(absolute=False)

search_program(program_name: str) -> str

Search for a program executable path by name.

from controlhub import search_program

path = search_program("notepad")
print(path)

path = search_program("chrome")
print(path)

path = search_program("word")
print(path)

controlhub.keyboard

click(x: int = None, y: int = None, button: str = 'left') -> None

Simulate a mouse click at the given coordinates or current position.

from controlhub import click

click()  # Click at current position
click(100, 200)  # Click at (100, 200)
click(300, 400, button='right')  # Right-click at (300, 400)

move(x: int = None, y: int = None) -> None

Move the mouse to the given coordinates.

from controlhub import move

move(500, 500)
move(0, 0)
move(1920, 1080)

drag(x: int = None, y: int = None, x1: int = None, y1: int = None, button: str = 'left', duration: float = 0) -> None

Drag the mouse from start to end coordinates.

from controlhub import drag

drag(100, 100, 200, 200)
drag(300, 300, 400, 400, button='right')
drag(500, 500, 600, 600, duration=1.5)

get_position() -> tuple[int, int]

Get the current mouse position.

from controlhub import get_position

pos = get_position()
print(pos)

x, y = get_position()
print(f"Mouse is at ({x}, {y})")

press(*keys: Union[str, Key]) -> None

Simulate pressing and releasing keys.

from controlhub import press

press('ctrl', 'c')  # Copy
press('ctrl', 'v')  # Paste
press('alt', 'tab')  # Switch window

hold(*keys: Union[str, Key])

Context manager to hold keys during a block.

from controlhub import hold, press

with hold('ctrl'):
    press('c')  # Ctrl+C

with hold('shift'):
    press('left')  # Select text

with hold('alt'):
    press('tab')  # Switch window

write(text: str) -> None

Type the given text.

from controlhub import write

write("Hello, world!")
write("This is automated typing.")
write("ControlHub is awesome!")

controlhub.web

download(url: str, directory: str = 'download') -> None

Download a file from a URL into a directory.

from controlhub import download

download("https://example.com/file.zip")
download("https://example.com/image.png", directory="images")
download("https://example.com/doc.pdf", directory="docs")

open_url(url: str) -> None

Open a URL in the default web browser.

from controlhub import open_url

open_url("https://www.google.com")
open_url("github.com")  # Will prepend http://
open_url("https://stackoverflow.com")

License

This project is licensed under the MIT License.

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

controlhub-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

controlhub-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file controlhub-0.1.0.tar.gz.

File metadata

  • Download URL: controlhub-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for controlhub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b013f96c2b4020a85ce80e0a320aa1e6632979c12767c8cad11fdabee33d52e0
MD5 e9b20338959b96cc447d0c335cfd09fb
BLAKE2b-256 0c5660bac5a512b835880b0c49ef6db40ca088e3e9b96fee8eb71cfde2c364f3

See more details on using hashes here.

File details

Details for the file controlhub-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: controlhub-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for controlhub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11dcaaa3308cf0e9793e00c8ddac2ad8e3c3190a96be2518dff19b219fcec1fa
MD5 77abee74d05f96db3a7de2aa16a4d069
BLAKE2b-256 cd17c95f11eff1f0bf6dac5c7fcb70e4613cf442f704138a687b068beec0abd4

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