安装:pip install autopy -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install autopy -i https://pypi.tuna.tsinghua.edu.cn/simple/
外网网络不好 换了国内源
结果:
'''官网:https://pypi.org/project/autopy/
说用
pip install -U autopy
测试能不能直接安装,我安装好了才看到的。。
如果失败,请安装rustup,然后运行:
$ rustup default nightly-2019-10-05
$ pip install -U setuptools-rust
$ pip install -U autopy
'''
测试:
import autopy
def test_foggy():
autopy.alert.alert("hello,world")
test_foggy()
结果:
开始体验:
1.控制鼠标
import autopy
def test_foggy():
autopy.alert.alert("hello,world")
def mouse_move_foggy(x,y):
autopy.mouse.move(x, y)
if __name__ == '__main__':
#test_foggy()
mouse_move_foggy(1,1)
然后鼠标位置就变了 跳到了左边屏幕(我的主屏)的右上角?
正常不是左上角吗?
官网测试函数:
import autopy
import math
import time
import random
import sys
def sine_mouse_wave():
"""
Moves the mouse in a sine wave from the left edge of
the screen to the right.
"""
width, height = autopy.screen.size()
height /= 2
height -= 10 # Stay in the screen bounds.
for x in range(int(width)):
y = int(height * math.sin((TWO_PI * x) / width) + height)
print(x,y)
autopy.mouse.move(x, y)
time.sleep(random.uniform(0.001, 0.003))
if __name__ == '__main__':
#test_foggy()
#mouse_move_foggy(10,550)
sine_mouse_wave()
结果:没错啊 是从左往右啊???????? 主屏结束就结束了没有跨屏。
具体原因现在不知道。不过在设置里两块显示屏对齐后就能上一个函数就能正常到主屏左上角了。
2.键盘:
import autopy
def str_o_foggy(s):
autopy.key.type_string(s, wpm=100)
if __name__ == '__main__':
#test_foggy()
#mouse_move_foggy(10,5)
#sine_mouse_wave()
str_o_foggy('hello world')
结果:直接在鼠标当前位置输入helloworld wpm是控制输入速度的。wpm=1000大概和祖安钢琴家差不多M>_<M。