python实现控制电脑鼠标和键盘,登录QQ的方法示例
本文实例讲述了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相关内容感兴趣的读者可查看本站专题:《Python进程与线程操作技巧总结》、《Python Socket编程技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》
希望本文所述对大家Python程序设计有所帮助。
赞 (0)