Skip to main content

xdoctl - Xdotool 命令包装器

xdoctl 通过包装 xdotool 提供的各种操作和命令,提供一种使用 Python 操作 xdotool 工具的方式。

如何安装

  • 直接从仓库安装:
    • pip install git+https://github.com/nukemiko/python-xdoctl
  • 或者到 发布页面 下载打包好的版本,然后使用 pip 安装

常用操作示例

导入包

>>> import xdoctl

鼠标操作

获取鼠标位置

>>> xdoctl.mouse.get_location()
MouseLocation(x=481, y=1088, screen=0, window=123732042)

改变鼠标位置,其后再次获取鼠标位置

>>> xdoctl.mouse.move(1920, 1080)
>>> xdoctl.mouse.get_location()
MouseLocation(x=1920, y=1080, screen=0, window=123732042)

模拟按下鼠标左键、右键和中键

>>> xdoctl.mouse.click(1)  # 鼠标左键
>>> xdoctl.mouse.click(3)  # 鼠标右键
>>> xdoctl.mouse.click(2)  # 鼠标中键

键盘操作

通过 keyboard.key_press() 模拟按下指定字符的行为

>>> xdoctl.keyboard.key_press('A')  # 输入单个字符
>>> xdoctl.keyboard.key_press('E', 'x', 'a', 'm', 'p', 'l', 'e')  # 输入一个单词
>>> xdoctl.keyboard.key_press(*list('Example'))  # 等效于 `keyboard.key_press('E', 'x', 'a', 'm', 'p', 'l', 'e')`
>>> xdoctl.keyboard.key_press(*list('This'), 'space', *list('is'), 'space', 'a', 'n', *list('example'))  # 输入一个句子

通过 keyboard.type_() 输入特定内容

使用此方法输入长文本,比 keyboard.key_press() 更高效和易用

>>> xdoctl.keyboard.type_('This is an example')

窗口操作

通过鼠标选择窗口,并获取其 windowid

>>> xdoctl.window.select_via_mouse()
123732042

通过 window.search() 和特定条件,获取一个 / 多个窗口的 windowid

>>> xdoctl.window.search('Konsole')
(138412036, 138412041, 138412039)

使用特定的 PID,通过 window.search(),获取一个 / 多个窗口的 windowid

>>> xdoctl.window.search(38616, pattern_is_pid=True)
(138412039,)

使用特定的 windowid,获取这个窗口的标题、PID、大小、位置等信息

>>> xdoctl.window.get_window_name(140509185)  # 窗口标题
'Visual Studio Code'
>>> xdoctl.window.get_window_pid(140509185)  # 窗口所属进程的 PID
43496
>>> xdoctl.window.get_window_geometry(140509185)  # 窗口的几何属性(包括位置、大小、所在屏幕等)
WindowGeometryAttributes(x=312, y=504, width=1848, height=888, screen=0)

移动窗口,其后获取窗口位置

>>> xdoctl.window.window_move(140509185, 100, 100)  # 移动窗口到 (100, 100);相对于坐标原点(位于屏幕左上角)移动
>>> xdoctl.window.get_window_geometry(140509185)
WindowGeometryAttributes(x=0, y=49, width=1848, height=888, screen=0)
>>> xdoctl.window.window_move(140509185, 800, 600, relative=True)  # 移动窗口到 (900, 700);相对于原窗口位置 (100, 100) 移动
>>> xdoctl.window.get_window_geometry(140509185)
WindowGeometryAttributes(x=312, y=504, width=1848, height=888, screen=0)

Metadata

Release files for python-xdoctl 0.1.0.post2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for python-xdoctl 0.1.0.post2
File Interpreter ABI Platform Actions
python_xdoctl-0.1.0.post2-py3.8.egg Legacy Egg format - - Details for python_xdoctl-0.1.0.post2-py3.8.egg
python_xdoctl-0.1.0.post2-py3-none-any.whl Python 3 none any Details for python_xdoctl-0.1.0.post2-py3-none-any.whl

Total release size: 27.9 kB

Release files / python_xdoctl-0.1.0.post2-py3.8.egg

Download URL python_xdoctl-0.1.0.post2-py3.8.egg
Size 18.1 kB
Tags Egg
SHA-256 checksum
How to use checksums
9f7608363d5085036c33623ef10292d5fb1c0773f9e244f6f19cc78c392c31b1
BLAKE2b-256 checksum
How to use checksums
94187a445f560730f6ffb802ca4886d6f23fbac9b54dca32421fdef55614ce96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / python_xdoctl-0.1.0.post2-py3-none-any.whl

Download URL python_xdoctl-0.1.0.post2-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
548d7f88a3c346603915b115774b074d2663ce35de1f6a99cf98aa8f69be192a
BLAKE2b-256 checksum
How to use checksums
3518502c15ae3db5d672fe5593a0d13c1940ec2933f133aaa041168a2709e72f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for python-xdoctl 0.1.0.post2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0.post2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page