python實現(xiàn)控制電腦鼠標(biāo)和鍵盤,登錄QQ的方法示例
本文實例講述了python實現(xiàn)控制電腦鼠標(biāo)和鍵盤,登錄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()
#點(diǎn)擊右下角刷新桌面圖標(biāo)
mouse.position = (1433, 884)
mouse.press(Button.left)
mouse.release(Button.left)
sleep(2)
#打開QQ(跟進(jìn)QQ具體路徑來設(shè)置)
os.startfile("C:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe")
mouse = Controller()
#讀取鼠標(biāo)位置
# sleep(5)
# print('當(dāng)前指針坐標(biāo)位置是{}'.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密碼指針坐標(biāo)位置是(765, 551)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python進(jìn)程與線程操作技巧總結(jié)》、《Python Socket編程技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
python反轉(zhuǎn)一個三位整數(shù)的多種實現(xiàn)方案
這篇文章主要介紹了python反轉(zhuǎn)一個三位整數(shù)的多種實現(xiàn)方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03
深入理解python中sort()與sorted()的區(qū)別
Python list內(nèi)置sort()方法用來排序,也可以用python內(nèi)置的全局sorted()方法來對可迭代的序列排序生成新的序列。這篇文章主要介紹了python中sort()與sorted()的區(qū)別,需要的朋友可以參考下2018-08-08

