Skip to main content

ydotool client implemented in Python

Project description

pydotool

A ydotool client implemented in Python. The aim of pydotool is to write automation scripts in an easy way.

Usage

  • click event
  • key event
  • mouse move event
  • type characters

How to Use

  • Install ydotoold. you may install it from your package manager, or build it from source.

  • Install pydotool. pip install python-ydotool

  • Write your automation script. Call init once in your program to connect to ydotoold

import pydotool
pydotool.init()

If you use another ydotoold socket than the default one (/tmp/.ydotool_socket), you can provide it in environment variable YDOTOOL_SOCKET, or pass it to init()

pydotool.init("/run/ydotoold/socket")

How to Implement the Examples in ydotool

Switch to tty1 (Ctrl+Alt+F1), wait 2 seconds, and type some words:

import time

from pydotool import KEY_F1, KEY_LEFTALT, KEY_LEFTCTRL, key_combination, init, type_string

init()  # call only once before using pydotool

key_combination([KEY_LEFTCTRL, KEY_LEFTALT, KEY_F1])
time.sleep(2)
type_string("echo Hey guys. This is Austin.")

Close a window in graphical environment (Alt+F4):

from pydotool import KEY_F4, KEY_LEFTALT

key_combination([KEY_LEFTALT, KEY_F4])

Relatively move mouse pointer to -100,100:

from pydotool import mouse_move
mouse_move((100, 100))

Move mouse pointer to 100,100:

mouse_move((100, 100), True)

Mouse right click:

from pydotool import right_click

right_click()

Mouse repeating left click:

from pydotool import click_sequence, ClickEnum

click_sequence([ClickEnum.LEFT_CLICK] * 5)

stdin is not natively supported, but you can implement it with python stdin.

Advanced Usage

There is no delay in pydotool API after the last event emitted.

for i in range(5):
    left_click()
    if i != 4:
        time.sleep(0.025)

# above code is equivalent to
click_sequence([ClickEnum.LEFT_CLICK] * 5)

Customize the delay time:

# Each click event is combined with "press" and "release", so there are totally 10 ydotool events, and 9 delays between each two consecutive events.
# the 9 delays are 10ms, 20ms, ..., 90ms.
click_sequence([ClickEnum.LEFT_CLICK] * 5, delay_sequence=list(range(10, 100, 10)))

Complex key operations:

# Ctrl+K and Ctrl+D without releasing Ctrl
key_seq([(KEY_LEFTCTRL, DOWN), (KEY_K, DOWN), (KEY_K, UP), (KEY_D, DOWN), (KEY_D, UP), (KEY_LEFTCTRL, UP)])

Control the press time when typing:

# Type "abcde", but hold 1 sec for each character.
# Note that long press may generate more content than expected.
type_string("abcde", hold_delay_ms=1000, each_char_delay_ms=20)
# possible output: 
# aaaaaaaaaaaabbbbbbbbbbbccccccccccccddddddddddddeeeeeeeeeeee

Long press key combination:

# Press Alt+F4 for 3 secs. Can close most of the apps. Not recommended to try this.
key_combination([KEY_LEFTALT, KEY_F4], press_ms=3000)

Using the low level API to send event:

# directly send an event using uinput_emit()
uinput_emit(EV_REL, REL_Y, 100, True)  # move 100 in y direction

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

python_ydotool-1.1.1.tar.gz (40.3 kB view details)

Uploaded Source

Built Distributions

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

python_ydotool-1.1.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

python_ydotool-1.1.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

python_ydotool-1.1.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

python_ydotool-1.1.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

File details

Details for the file python_ydotool-1.1.1.tar.gz.

File metadata

  • Download URL: python_ydotool-1.1.1.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_ydotool-1.1.1.tar.gz
Algorithm Hash digest
SHA256 b9b7c521998c7647b49e91b0893c99dbfe0d14d8523cfc7cadf90b3166336ec5
MD5 83ad38ba7320d26e924ebf6c21e4ce67
BLAKE2b-256 4eb0b969ac74040ea4510321a31247588b64cc257acd2ce95e6269d01314f4bd

See more details on using hashes here.

File details

Details for the file python_ydotool-1.1.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_ydotool-1.1.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ae214b31c447bd8a89aca6b45882530fd2c498a6e5e59140453cb22bb77e75c
MD5 754f80b45a0eae8179e2941e7a0deedc
BLAKE2b-256 d2725222cef47aad7221f29a213e5083cc986dd7cfa39f421b59b2bbd68e47ef

See more details on using hashes here.

File details

Details for the file python_ydotool-1.1.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_ydotool-1.1.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e46676d117e398a658a77b62289686f2bcb66e25ca382e6f1872bbc80007e4d
MD5 81a74eda56fc3254eb08e34e4fb739a2
BLAKE2b-256 34c80d9aa2103ee00a188f74bd51e45c9c23b8a66cc94f99a2c714d539dc745d

See more details on using hashes here.

File details

Details for the file python_ydotool-1.1.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_ydotool-1.1.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 de2d5e56b1646c516fbe036c2576e59112a582e471df40f93feb0df3534f03df
MD5 a43864677f2cd129ddc35d55a2f8d38b
BLAKE2b-256 3875aff189539c3c149da769a90b368572b58bb379d4080219dc4e7d4c6b8473

See more details on using hashes here.

File details

Details for the file python_ydotool-1.1.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_ydotool-1.1.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 300c6ea1684d734723971d4870a02204827b97ce31b0d9fd6e887980ae1af1ea
MD5 91fa6c7c9bd8064ad97c9ba5e197a613
BLAKE2b-256 b24a8152ebdad79949adfb20835decaaa89f18ecf1b9a588a26a183db60bfe9b

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