2022-02-19 07:10:20 +08:00
|
|
|
import multiprocessing
|
2022-01-25 21:31:18 +08:00
|
|
|
import tkinter
|
|
|
|
from identify import *
|
|
|
|
from tkinter.filedialog import *
|
|
|
|
from win32com.client import Dispatch
|
|
|
|
import win32con
|
|
|
|
import win32api
|
|
|
|
import time
|
|
|
|
import os
|
|
|
|
|
|
|
|
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键
|
2022-03-21 20:53:29 +08:00
|
|
|
win32api.keybd_event(82, 0, 0, 0) # 代表按下f键
|
2022-01-25 21:31:18 +08:00
|
|
|
time.sleep(0.02)
|
|
|
|
win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键
|
2022-03-21 20:53:29 +08:00
|
|
|
win32api.keybd_event(82, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键
|
|
|
|
|
|
|
|
|
|
|
|
def control_writing(m, position_x, position_y):
|
|
|
|
m.move(position_x, position_y)
|
2022-01-25 21:31:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
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-03-21 20:53:29 +08:00
|
|
|
def control_thread(value, array):
|
2022-02-19 07:10:20 +08:00
|
|
|
last_time = 0.0
|
2022-02-20 09:55:18 +08:00
|
|
|
step = 0
|
2022-03-21 20:53:29 +08:00
|
|
|
mouse = PyMouse()
|
|
|
|
|
2022-01-25 21:31:18 +08:00
|
|
|
while 1:
|
2022-02-20 09:55:18 +08:00
|
|
|
# print("step = " + str(step))
|
2022-02-19 07:10:20 +08:00
|
|
|
# print("control_thread")
|
|
|
|
now_time = time.time()
|
2022-02-20 09:55:18 +08:00
|
|
|
# time.sleep(0.1)
|
2022-02-19 07:10:20 +08:00
|
|
|
# print(end - start)
|
2022-03-21 20:53:29 +08:00
|
|
|
# print("***********array************")
|
|
|
|
# print(array)
|
|
|
|
# print("***********array************")
|
|
|
|
control_flag = value.value
|
|
|
|
if step == 2:
|
|
|
|
if control_flag == 4:
|
|
|
|
# print("inininininininininininininininininininininininin")
|
|
|
|
position_x = int(mouse.screen_size()[0] / array[2] * array[0])
|
|
|
|
position_y = int(mouse.screen_size()[1] / array[3] * array[1])
|
|
|
|
control_writing(mouse, position_x, position_y)
|
|
|
|
elif control_flag == 5:
|
|
|
|
step = 1
|
|
|
|
control_ppt_end()
|
|
|
|
last_time = now_time
|
|
|
|
# print("step to 11111111111111111")
|
|
|
|
continue
|
2022-02-19 07:10:20 +08:00
|
|
|
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()
|
2022-02-20 09:55:18 +08:00
|
|
|
print("control_flag = " + str(control_flag))
|
2022-03-21 20:53:29 +08:00
|
|
|
# print("main.step = " + str(step))
|
2022-02-20 09:55:18 +08:00
|
|
|
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")
|
2022-03-21 20:53:29 +08:00
|
|
|
elif control_flag == 3:
|
2022-02-20 09:55:18 +08:00
|
|
|
control_page_down()
|
|
|
|
# print("control_flag == 3")
|
2022-03-21 20:53:29 +08:00
|
|
|
elif control_flag == 4:
|
|
|
|
control_open_pencil()
|
|
|
|
step = 2
|
|
|
|
elif control_flag == 5:
|
2022-02-20 09:55:18 +08:00
|
|
|
control_ppt_end()
|
2022-03-21 20:53:29 +08:00
|
|
|
# print("end!end!end!end!end!end!end!end!end!end!end!")
|
2022-02-20 09:55:18 +08:00
|
|
|
# print("control_flag == 4")
|
|
|
|
step = 0
|
2022-01-25 21:31:18 +08:00
|
|
|
# if control_flag == 5:
|
|
|
|
# control_open_pencil()
|
|
|
|
# if control_flag == 6:
|
|
|
|
# control_draw()
|
|
|
|
|
|
|
|
|
2022-03-21 20:53:29 +08:00
|
|
|
def identify_thread(value, array):
|
|
|
|
identify = Identify(value, array)
|
2022-02-19 07:10:20 +08:00
|
|
|
identify.begin()
|
|
|
|
|
|
|
|
|
2022-03-21 20:53:29 +08:00
|
|
|
def show_thread(value, array):
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2022-01-25 21:31:18 +08:00
|
|
|
def open_file():
|
2022-03-21 20:53:29 +08:00
|
|
|
file_path = askopenfilename(title=u'选择文件')
|
|
|
|
# file_path = askopenfilename(title=u'选择文件', initialdir=(os.path.expanduser('H:/')))
|
2022-01-25 21:31:18 +08:00
|
|
|
open_ppt(file_path)
|
2022-03-21 20:53:29 +08:00
|
|
|
value = multiprocessing.Value('i', 0)
|
|
|
|
array = multiprocessing.Array('i', 4)
|
|
|
|
# array2 = multiprocessing.Array()
|
|
|
|
p1 = multiprocessing.Process(target=identify_thread, args=(value, array))
|
|
|
|
p2 = multiprocessing.Process(target=control_thread, args=(value, array))
|
|
|
|
# p3 = multiprocessing.Process(target=show_thread, args=(value, array))
|
2022-02-19 07:10:20 +08:00
|
|
|
p1.start()
|
|
|
|
p2.start()
|
2022-03-21 20:53:29 +08:00
|
|
|
# p3.start()
|
2022-02-19 07:10:20 +08:00
|
|
|
# identify_t = threading.Thread(target=identify_thread)
|
2022-03-21 20:53:29 +08:00
|
|
|
# print("control_flag1 = " + str(control_flag))
|
2022-02-19 07:10:20 +08:00
|
|
|
# control_t = threading.Thread(target=control_thread)
|
2022-03-21 20:53:29 +08:00
|
|
|
# print("control_flag2 = " + str(control_flag))
|
2022-02-19 07:10:20 +08:00
|
|
|
# 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 # 不显示,不警告
|
2022-03-21 20:53:29 +08:00
|
|
|
ppt.Presentations.Open(file_path)
|
2022-01-25 21:31:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2022-04-17 15:23:46 +08:00
|
|
|
window = tkinter.Tk()
|
|
|
|
window.title("会议PPT选择")
|
|
|
|
window.geometry("200x100")
|
2022-01-25 21:31:18 +08:00
|
|
|
bt1 = tkinter.Button(window, text='打开文件', width=15, height=15, command=open_file)
|
|
|
|
bt1.pack()
|
|
|
|
window.mainloop()
|