Python操控键盘鼠标
- 操控键盘
- 操控鼠标
操控键盘
import pyautogui
#typewrite()无法输入中文内容,中英文混合的只能输入英文
#interval设置文本输入速度,默认值为0
pyautogui.typewrite('你好,world!',interval=0.5)
操控鼠标
import pyautogui as pgtry:while True:x, y = pg.position()print(str(x) + " " + str(y)) #输出鼠标位置if 1746 < x < 1800 and 2 < y < 33:pg.click()#左键单击if 1200 < x < 1270 and 600 < y < 620:pg.click(button='right')#右键单击if 1646 < x < 1700 and 2 < y < 33:pg.doubleClick()#左键双击except KeyboardInterrupt:print("\n")