python控制电脑鼠标和键盘,登录QQ

import os
from pynput.mouse import Button,Controller
from pynput.keyboard import Key
from pynput.keyboard import Controller as W
from time import sleep

mouse = Controller()
keyboard = W()

#点击右下角刷新桌面图标
mouse.position = (1433, 884)
mouse.press(Button.left)
mouse.release(Button.left)
sleep(2)

#打开QQ(跟进QQ具体路径来设置)
os.startfile("C:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe")
mouse = Controller()

#读取鼠标位置
# sleep(5)
# print('当前指针坐标位置是{}'.format(mouse.position))

sleep(2)
mouse.position = (654, 340)
mouse.press(Button.left)
mouse.release(Button.left)
sleep(1)
mouse.position = (729, 489)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
#输入QQ账号
keyboard.type("QQ账号")
sleep(1)

#输入密码
keyboard.press(Key.tab)
keyboard.release(Key.tab)
keyboard.type("QQ密码")
#QQ密码指针坐标位置是(765, 551)

keyboard.press(Key.enter)
keyboard.release(Key.enter)

你可能感兴趣的:(python程序)