import multiprocessing import tkinter import cv2 import identify from identify import * from tkinter.filedialog import * import threading # import pymouse from tkinter import * from tkinter import ttk import tkinter.filedialog as dir import queue from tkinter.messagebox import showinfo import win32com from win32com.client import Dispatch from pptx import Presentation from selenium import webdriver from selenium.webdriver.common.keys import Keys import win32con import win32api import time import os import string window = tkinter.Tk() window.title('窗口标题') window.geometry('200x50') control_flag = 0 x = 0 y = 0 def show(): win32api.keybd_event(116, 0, 0, 0) # 代表按下f键 time.sleep(0.02) win32api.keybd_event(116, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 time.sleep(2) win32api.keybd_event(34, 0, 0, 0) # 代表按下f键 time.sleep(0.02) win32api.keybd_event(34, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 def control_page_up(): win32api.keybd_event(38, 0, 0, 0) # 代表按下f键 time.sleep(0.02) win32api.keybd_event(38, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 def control_page_down(): win32api.keybd_event(40, 0, 0, 0) # 代表按下f键 time.sleep(0.02) win32api.keybd_event(40, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 def control_ppt_begin(): win32api.keybd_event(116, 0, 0, 0) # 代表按下f键 win32api.keybd_event(16, 0, 0, 0) # 代表按下f键 time.sleep(0.02) win32api.keybd_event(116, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 win32api.keybd_event(16, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 def control_ppt_end(): win32api.keybd_event(27, 0, 0, 0) # 代表按下f键 time.sleep(0.02) win32api.keybd_event(27, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 def control_open_pencil(): win32api.keybd_event(17, 0, 0, 0) # 代表按下f键 win32api.keybd_event(80, 0, 0, 0) # 代表按下f键 time.sleep(0.02) win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 win32api.keybd_event(80, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 def control_draw(): global x, y # m = pymouse.PyMouse() # m.move(x, y) # win32api.keybd_event(40, 0, 0, 0) # 代表按下f键 # time.sleep(0.02) # win32api.keybd_event(40, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键 # class Control: # def __init__(self, control_flag): # self.control_flag = control_flag # def control_thread(v, flag): last_time = 0.0 step = 0 while 1: # print("step = " + str(step)) # print("control_thread") now_time = time.time() # time.sleep(0.1) # print(end - start) control_flag = v.value if now_time - last_time < 1: continue last_time = now_time # if control_flag in range(1, 2, 3, 4, 5): # time.sleep(2) # elif control_flag == 6: # time.sleep(0.05) # start = time.time() print("control_flag = " + str(control_flag)) if step == 0 and control_flag == 1: control_ppt_begin() # print("control_flag == 1") step = 1 elif step == 1: if control_flag == 2: control_page_up() # print("control_flag == 2") if control_flag == 3: control_page_down() # print("control_flag == 3") if control_flag == 4: control_ppt_end() # print("control_flag == 4") step = 0 # if control_flag == 5: # control_open_pencil() # if control_flag == 6: # control_draw() def identify_thread(v, flag): identify = Identify(v) identify.begin() def open_file(): file_path = askopenfilename(title=u'选择文件', initialdir=(os.path.expanduser('H:/'))) open_ppt(file_path) v = multiprocessing.Value('i', 0) p1 = multiprocessing.Process(target=identify_thread, args=(v, 0)) p2 = multiprocessing.Process(target=control_thread, args=(v, 0)) p1.start() p2.start() # identify_t = threading.Thread(target=identify_thread) # # print("control_flag1 = " + str(control_flag)) # control_t = threading.Thread(target=control_thread) # # print("control_flag2 = " + str(control_flag)) # identify_t.setDaemon(True) # control_t.setDaemon(True) # identify_t.start() # control_t.start() def open_ppt(file_path): ppt = Dispatch('PowerPoint.Application') ppt.Visible = 1 # 后台运行 ppt.DisplayAlerts = 0 # 不显示,不警告 # pptSel = ppt.Presentations.Open(file_path) if __name__ == '__main__': bt1 = tkinter.Button(window, text='打开文件', width=15, height=15, command=open_file) bt1.pack() window.mainloop()