模拟键盘和复制文件
from pykeyboard import PyKeyboard
import time
import glob
import os
import shutil
import threading
def key_click_f1(t=1):
k = PyKeyboard()
while True:
print(‘点击F1‘)
k.tap_key(k.function_keys[1]) # 点击功能键F5
time.sleep(1)
def copy_file(files_map_list,t=30):
while True:
for file_map in files_map_list:
source_dir, aim_dir, file_type = file_map
glob_source_path = os.path.join(source_dir,‘*.{}‘.format(file_type))
glob_aim_path = os.path.join(aim_dir,‘*.{}‘.format(file_type))
source_file_paths = glob.glob(glob_source_path)
aim_file_paths = glob.glob(glob_aim_path)
if not aim_file_paths:
print(files_map_list)
for source_path in source_file_paths:
file_name = os.path.basename(source_path)
aim_path = os.path.join(aim_dir,file_name)
shutil.copyfile(source_path,aim_path)
time.sleep(1)
f1_t = threading.Thread(target=key_click_f1,args=(2,),daemon=True)
args_map = [
[r‘C:\Users\WangLin\Downloads‘,r‘D:\ccc‘, ‘png‘],
]
copy_t = threading.Thread(target=copy_file,args=(args_map,),daemon=True)
t_list = []
# t_list.append(f1_t)
t_list.append(copy_t)
for t in t_list:
t.start()
for t in t_list:
t.join()
模拟键盘和复制文件