Xdotool 命令包装器
Project description
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
File details
Details for the file python_xdoctl-0.1.0.post2-py3.8.egg
.
File metadata
- Download URL: python_xdoctl-0.1.0.post2-py3.8.egg
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f7608363d5085036c33623ef10292d5fb1c0773f9e244f6f19cc78c392c31b1 |
|
MD5 | 1dc4fb6d61575a16ae87a9a970c21a65 |
|
BLAKE2b-256 | 94187a445f560730f6ffb802ca4886d6f23fbac9b54dca32421fdef55614ce96 |
File details
Details for the file python_xdoctl-0.1.0.post2-py3-none-any.whl
.
File metadata
- Download URL: python_xdoctl-0.1.0.post2-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 548d7f88a3c346603915b115774b074d2663ce35de1f6a99cf98aa8f69be192a |
|
MD5 | 73e93935c6967d5ab72b7fea294ed2eb |
|
BLAKE2b-256 | 3518502c15ae3db5d672fe5593a0d13c1940ec2933f133aaa041168a2709e72f |