Change keyboard module

This commit is contained in:
naibo 2023-07-09 08:59:11 +08:00
parent 261fb13006
commit bb6e2b2881
5 changed files with 36 additions and 32 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,7 @@
"justMyCode": true,
// "args": ["--id", "[7]", "--read_type", "remote", "--headless", "0"]
// "args": ["--id", "[9]", "--read_type", "remote", "--headless", "0", "--saved_file_name", "YOUTUBE"]
"args": ["--id", "[6]", "--headless", "0", "--user_data", "1"]
"args": ["--id", "[3]", "--headless", "0", "--user_data", "1"]
}
]
}

View File

@ -39,10 +39,11 @@ import os
from commandline_config import Config
import pytesseract
from PIL import Image
from pynput.keyboard import Key, Listener
# import uuid
from threading import Thread, Event
from myChrome import MyChrome, MyUCChrome
from utils import check_pause, download_image, get_output_code, isnull, lowercase_tags_in_xpath, myMySQL, new_line, on_press, on_release_creator, write_to_csv, write_to_excel
from utils import download_image, get_output_code, isnull, lowercase_tags_in_xpath, myMySQL, new_line, on_press, on_release_creator, write_to_csv, write_to_excel
desired_capabilities = DesiredCapabilities.CHROME
desired_capabilities["pageLoadStrategy"] = "none"
@ -1504,19 +1505,20 @@ if __name__ == '__main__':
threads.append(thread)
thread.start()
# Set the pause operation
if sys.platform != "linux":
Thread(target=check_pause, args=("p", event)).start()
else:
from pynput.keyboard import Key, Listener
# 使用监听器监听键盘输入
with Listener(on_press=on_press, on_release=on_release_creator(event)) as listener:
listener.join()
time.sleep(5)
# if sys.platform != "linux":
# Thread(target=check_pause, args=("p", event)).start()
# else:
time.sleep(3)
print("\n\n----------------------------------")
print("正在运行任务,按键盘p键可暂停任务的执行以便手工操作浏览器如输入验证码如果想恢复任务的执行请再次按p键。")
print("正在运行任务按键盘p键可暂停任务的执行以便手工操作浏览器如输入验证码如果想恢复任务的执行请再次按p键。")
print("Running task, long press 'p' to pause the task for manual operation of the browser such as entering the verification code; If you want to resume the execution of the task, please long press 'p' again.")
print("----------------------------------\n\n")
# 使用监听器监听键盘输入
with Listener(on_press=on_press, on_release=on_release_creator(event)) as listener:
listener.join()
for thread in threads:
thread.join()

View File

@ -7,7 +7,7 @@ import os
import re
import time
import uuid
import keyboard
# import keyboard
from openpyxl import Workbook, load_workbook
import requests
from urllib.parse import urlparse
@ -24,41 +24,41 @@ def is_valid_url(url):
def lowercase_tags_in_xpath(xpath):
return re.sub(r"([A-Z]+)(?=[\[\]//]|$)", lambda x: x.group(0).lower(), xpath)
def on_press(key):
pass
def on_release_creator(event):
def on_release(key):
try:
if key.char == 'p': # 当按下esc键时退出监听
if event._flag == False:
print("任务执行中,按p键暂停执行。")
print("任务执行中,按p键暂停执行。")
print("Task is running, long press 'p' to pause.")
# 设置Event的值为True使得线程b可以继续执行
event.set()
else:
# 设置Event的值为False使得线程b暂停执行
print("任务已暂停,按p键继续执行...")
print("任务已暂停,按p键继续执行...")
print("Task paused, press 'p' to continue...")
event.clear()
except:
pass
return on_release
def check_pause(key, event):
while True:
if keyboard.is_pressed(key): # 按下p键暂停程序
if event._flag == False:
print("任务执行中长按p键暂停执行。")
print("Task is running, long press 'p' to pause.")
# 设置Event的值为True使得线程b可以继续执行
event.set()
else:
# 设置Event的值为False使得线程b暂停执行
print("任务已暂停长按p键继续执行...")
print("Task paused, press 'p' to continue...")
event.clear()
time.sleep(1) # 每秒检查一次
def on_press(key):
pass
# def check_pause(key, event):
# while True:
# if keyboard.is_pressed(key): # 按下p键暂停程序
# if event._flag == False:
# print("任务执行中长按p键暂停执行。")
# print("Task is running, long press 'p' to pause.")
# # 设置Event的值为True使得线程b可以继续执行
# event.set()
# else:
# # 设置Event的值为False使得线程b暂停执行
# print("任务已暂停长按p键继续执行...")
# print("Task paused, press 'p' to continue...")
# event.clear()
# time.sleep(1) # 每秒检查一次
def download_image(url, save_directory):