2022-02-19 07:10:20 +08:00
|
|
|
import multiprocessing
|
2022-01-25 21:31:18 +08:00
|
|
|
import tkinter
|
|
|
|
|
|
|
|
import cv2
|
|
|
|
|
2022-02-19 07:10:20 +08:00
|
|
|
import identify
|
2022-01-25 21:31:18 +08:00
|
|
|
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
|
2022-02-19 07:10:20 +08:00
|
|
|
|
2022-01-25 21:31:18 +08:00
|
|
|
# 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键
|
|
|
|
|
2022-02-19 07:10:20 +08:00
|
|
|
# class Control:
|
|
|
|
# def __init__(self, control_flag):
|
|
|
|
# self.control_flag = control_flag
|
|
|
|
#
|
|
|
|
|
2022-01-25 21:31:18 +08:00
|
|
|
|
2022-02-19 07:10:20 +08:00
|
|
|
def control_thread(v, flag):
|
|
|
|
last_time = 0.0
|
2022-01-25 21:31:18 +08:00
|
|
|
while 1:
|
2022-02-19 07:10:20 +08:00
|
|
|
# print("control_thread")
|
|
|
|
now_time = time.time()
|
|
|
|
time.sleep(0.1)
|
|
|
|
# print(end - start)
|
|
|
|
if now_time - last_time < 1:
|
|
|
|
continue
|
|
|
|
last_time = now_time
|
2022-01-25 21:31:18 +08:00
|
|
|
# if control_flag in range(1, 2, 3, 4, 5):
|
|
|
|
# time.sleep(2)
|
|
|
|
# elif control_flag == 6:
|
|
|
|
# time.sleep(0.05)
|
2022-02-19 07:10:20 +08:00
|
|
|
# start = time.time()
|
|
|
|
print("control_flag = " + str(v.value))
|
|
|
|
control_flag = v.value
|
|
|
|
# if control_flag == 1:
|
|
|
|
# control_ppt_begin()
|
2022-02-19 15:26:22 +08:00
|
|
|
# if control_flag == 2:
|
|
|
|
# control_page_up()
|
|
|
|
# if control_flag == 3:
|
|
|
|
# control_page_down()
|
2022-02-19 07:10:20 +08:00
|
|
|
# if control_flag == 4:
|
|
|
|
# control_ppt_end()
|
2022-01-25 21:31:18 +08:00
|
|
|
# if control_flag == 5:
|
|
|
|
# control_open_pencil()
|
|
|
|
# if control_flag == 6:
|
|
|
|
# control_draw()
|
|
|
|
|
|
|
|
|
2022-02-19 07:10:20 +08:00
|
|
|
def identify_thread(v, flag):
|
|
|
|
identify = Identify(v)
|
|
|
|
identify.begin()
|
|
|
|
|
|
|
|
|
2022-01-25 21:31:18 +08:00
|
|
|
def open_file():
|
|
|
|
file_path = askopenfilename(title=u'选择文件', initialdir=(os.path.expanduser('H:/')))
|
|
|
|
open_ppt(file_path)
|
2022-02-19 07:10:20 +08:00
|
|
|
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()
|
2022-01-25 21:31:18 +08:00
|
|
|
|
2022-02-19 07:10:20 +08:00
|
|
|
|
|
|
|
def open_ppt(file_path):
|
|
|
|
ppt = Dispatch('PowerPoint.Application')
|
|
|
|
ppt.Visible = 1 # 后台运行
|
|
|
|
ppt.DisplayAlerts = 0 # 不显示,不警告
|
|
|
|
# pptSel = ppt.Presentations.Open(file_path)
|
2022-01-25 21:31:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
bt1 = tkinter.Button(window, text='打开文件', width=15, height=15, command=open_file)
|
|
|
|
bt1.pack()
|
|
|
|
window.mainloop()
|