Python控制鼠標(biāo)鍵盤代碼實(shí)例
python控制鼠標(biāo)鍵盤其實(shí)很容易,我們?cè)趯懗绦虻臅r(shí)候很多時(shí)候會(huì)用的到!
python控制鼠標(biāo)鍵盤步驟及代碼
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()
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python利用matplotlib模塊數(shù)據(jù)可視化繪制3D圖
matplotlib是python最著名的繪圖庫,它提供了一整套和matlab相似的命令A(yù)PI,十分適合交互式地行制圖,下面這篇文章主要給大家介紹了關(guān)于Python利用matplotlib模塊數(shù)據(jù)可視化實(shí)現(xiàn)3D圖的相關(guān)資料,需要的朋友可以參考下2022-02-02
Python 實(shí)現(xiàn)國產(chǎn)SM3加密算法的示例代碼
這篇文章主要介紹了Python 實(shí)現(xiàn)國產(chǎn)SM3加密算法的示例代碼,幫助大家更好的理解和學(xué)習(xí)密碼學(xué),感興趣的朋友可以了解下2020-09-09
Python利用手勢(shì)識(shí)別實(shí)現(xiàn)貪吃蛇游戲
想必大家都玩過貪吃蛇的游戲吧:通過操縱蛇的移動(dòng)方向能夠讓蛇吃到隨機(jī)出現(xiàn)的食物,吃到的食物越多,蛇就會(huì)變得越長。本文將使用手勢(shì)識(shí)別來完成貪吃蛇這個(gè)簡單的游戲,感興趣的可以了解一下2022-04-04
Python實(shí)現(xiàn)設(shè)計(jì)模式之單例模式詳解
這篇文章主要介紹了Python實(shí)現(xiàn)設(shè)計(jì)模式之單例模式詳解,設(shè)計(jì)模式是指軟件設(shè)計(jì)問題的推薦方案,設(shè)計(jì)模式一般是描述如何組織代碼和使用最佳實(shí)踐來解決常見的設(shè)計(jì)問題,需謹(jǐn)記一點(diǎn):設(shè)計(jì)模式是高層次的方案,并不關(guān)注具體的實(shí)現(xiàn)細(xì)節(jié),比如算法和數(shù)據(jù)結(jié)構(gòu),需要的朋友可以參考下2023-09-09
非常詳細(xì)的Django連接mysql數(shù)據(jù)庫步驟記錄
我的Mysql中已經(jīng)有了項(xiàng)目需要使用的相關(guān)數(shù)據(jù)庫,現(xiàn)在需要通過django來獲取Mysql里的數(shù)據(jù)并使用,下面這篇文章主要給大家介紹了關(guān)于非常詳細(xì)的Django連接mysql數(shù)據(jù)庫步驟,需要的朋友可以參考下2022-10-10
Python實(shí)用秘技之快速優(yōu)化導(dǎo)包順序詳解
這篇文章主要來和大家分享一個(gè)Python中的實(shí)用秘技,那就是如何快速優(yōu)化導(dǎo)包順序,文中的示例代碼簡潔易懂,快跟隨小編一起學(xué)習(xí)起來吧2023-06-06
Python實(shí)現(xiàn)在不同坐標(biāo)系中繪制曲線
這篇文章主要為大家學(xué)習(xí)介紹了Python如何實(shí)現(xiàn)在不同坐標(biāo)系中繪制曲線,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起了解一下2023-07-07

