python 按键精灵 离线_python,PyAutoGUI,自动操作鼠标键盘,类似按键精灵
三個文件需在同一個文件夾下面,文件夾的位置無要求。
1.第一個文件,trial.py,python代碼調用PyAutoGUI操作鼠標鍵盤。可以通過修改start_time和end_time來確定程序自動開始和結束的時間(24小時制)。
import pyautogui as ag
import datetime
import random
import time
import string
# 開始結束時間
start_time = 14
end_time = 15
# 屏幕尺寸
width, height = ag.size()
width_half = int(width / 2)
height_half = int(height / 2)
width_part = int(width / 4)
height_part = int(height / 4)
# 鼠標隨機移動10秒,以表示程序已經開始運行
for i in range(10):
# 生成坐標
x = random.randint(1, width)
y = random.randint(1, height)
# 移動鼠標
ag.moveTo(x, y, duration=1)
# 循環
while 1:
# 獲取當前時間
my_hour = datetime.datetime.now().hour
# 若在指定時間內
if start_time <= my_hour < end_time:
# 鼠標隨機移動
my_random = random.randint(0, 10)
for i in range(my_random):
# 生成坐標
x = random.randint(1, width)
y = random.randint(1, height)
# 移動鼠標
ag.moveTo(x, y, duration=0.25)
# 暫停隨機時間
my_random = random.randint(0, 10)
time.sleep(my_random)
# 鍵盤隨機按鍵
my_random = random.randint(0, 10)
my_str = random.sample(string.ascii_letters, my_random)
for i in range(my_random):
ag.typewrite(my_str[i])
ag.typewrite(['backspace'])
# 暫停隨機時間
my_random = random.randint(0, 10)
time.sleep(my_random)
2.第二個文件,black.bat,借助命令提示符運行程序。運行時將顯示命令提示符的黑窗口。
python .\\trial.py
3.第三個文件,隱藏黑框.vbs,調用black.bat程序,但不顯示命令提示符的黑窗口。
set ws=WScript.CreateObject("WScript.Shell")
ws.Run ".\\black.bat",0
總結
以上是生活随笔為你收集整理的python 按键精灵 离线_python,PyAutoGUI,自动操作鼠标键盘,类似按键精灵的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql数据库安装2017_mysql
- 下一篇: python调用窗口_如何调用一个函数并