Python控制鼠標鍵盤代碼實例
更新時間:2020年12月08日 10:40:36 作者:GZH媛程序
這篇文章主要介紹了Python控制鼠標鍵盤代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
python控制鼠標鍵盤其實很容易,我們在寫程序的時候很多時候會用的到!
python控制鼠標鍵盤步驟及代碼
1、安裝類庫
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()
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
python讀取word文檔,插入mysql數(shù)據(jù)庫的示例代碼
今天小編就為大家分享一篇python讀取word文檔,插入mysql數(shù)據(jù)庫的示例代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11python時間序列數(shù)據(jù)轉為timestamp格式的方法
這篇文章主要介紹了python時間序列數(shù)據(jù)轉為timestamp格式的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-08-08Python三十行代碼實現(xiàn)簡單人臉識別的示例代碼
這篇文章主要介紹了Python三十行代碼實現(xiàn)簡單人臉識別的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-03-03