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,randompyautogui.PAUSE = 3pyautogui.FAILSAFE = Truewidth, 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)聽(tīng)用戶鍵盤操作
from pynput.keyboard import Listenerimport 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í)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. JavaScript數(shù)據(jù)類型對(duì)函數(shù)式編程的影響示例解析2. vue實(shí)現(xiàn)將自己網(wǎng)站(h5鏈接)分享到微信中形成小卡片的超詳細(xì)教程3. 使用css實(shí)現(xiàn)全兼容tooltip提示框4. div的offsetLeft與style.left區(qū)別5. html清除浮動(dòng)的6種方法示例6. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)7. CSS代碼檢查工具stylelint的使用方法詳解8. 不要在HTML中濫用div9. 利用CSS3新特性創(chuàng)建透明邊框三角10. 詳解CSS偽元素的妙用單標(biāo)簽之美
