Python控制鼠標(biāo)鍵盤代碼實(shí)例
python控制鼠標(biāo)鍵盤其實(shí)很容易,我們?cè)趯懗绦虻臅r(shí)候很多時(shí)候會(huì)用的到!
python控制鼠標(biāo)鍵盤步驟及代碼
1、安裝類庫(kù)
pip install pyautogui
2、代碼:
import pyautogui,time,random pyautogui.PAUSE = 3 pyautogui.FAILSAFE = True width, height = pyautogui.size() #print(str(width)) #print(str(height)) def drawRct(): for i in range(10): pyautogui.moveTo(300, 300, duration=0.25) pyautogui.moveTo(400, 300, duration=0.25) pyautogui.moveTo(400, 400, duration=0.25) pyautogui.moveTo(300, 400, duration=0.25) def mouseScroll(): time.sleep(5) for i in range(10): pyautogui.scroll(-200) time.sleep(2) def getXy(): try: while True: x, y = pyautogui.position() print(x,y) except KeyboardInterrupt: print('\nExit.') def playVideo(x,y): for i in range(4): pyautogui.click(x,y) x=x+240 playAndComment() def playAndComment(): time.sleep(random.randint(5,15)) pyautogui.scroll(-400) pyautogui.scroll(-400) pyautogui.click(200,300) pyautogui.typewrite('very good!') pyautogui.click(900,400) pyautogui.click(710,16) if __name__ == '__main__': time.sleep(5) pyautogui.scroll(-300) for i in range(9): print(str(i)) time.sleep(random.randint(3,5)) #pyautogui.click(360,16) pyautogui.scroll(-300) time.sleep(random.randint(1,5)) playVideo(404,330)
直接監(jiān)聽用戶鍵盤操作
from pynput.keyboard import Listener import logging location = "./" logging.basicConfig( filename=(location+"keylogger.txt"), format="%(message)s", level=logging.DEBUG) def press(key): logging.info(key) with Listener(on_press = press) as listener: print('The program begins to watch the action of keyboard:') listener.join()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python非阻塞式后臺(tái)如何運(yùn)行bat腳本
這篇文章主要介紹了python非阻塞式后臺(tái)如何運(yùn)行bat腳本問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06python讀取word文檔,插入mysql數(shù)據(jù)庫(kù)的示例代碼
今天小編就為大家分享一篇python讀取word文檔,插入mysql數(shù)據(jù)庫(kù)的示例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-11-11python 日志模塊 日志等級(jí)設(shè)置失效的解決方案
這篇文章主要介紹了python 日志模塊 日志等級(jí)設(shè)置失效的問題及解決方案,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05python時(shí)間序列數(shù)據(jù)轉(zhuǎn)為timestamp格式的方法
這篇文章主要介紹了python時(shí)間序列數(shù)據(jù)轉(zhuǎn)為timestamp格式的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08Python三十行代碼實(shí)現(xiàn)簡(jiǎn)單人臉識(shí)別的示例代碼
這篇文章主要介紹了Python三十行代碼實(shí)現(xiàn)簡(jiǎn)單人臉識(shí)別的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03