-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloseApps.py
110 lines (84 loc) · 2.99 KB
/
closeApps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from pywinauto import application, mouse
import os
import sys
import time
# from dragonfly import Window
import ctypes
import win32gui
import win32api
from Misc import processArguments
def main():
params = {
'win_title': 'PDF-XChange Editor',
'mode': 0,
'wait_t': 10,
'scp_dst': '',
'auth_path': '',
'dst_path': '.',
'scp_path': '.',
'scp_name': 'grs',
}
processArguments(sys.argv[1:], params)
win_title = params['win_title']
# mode = params['mode']
# wait_t = params['wait_t']
# scp_dst = params['scp_dst']
# auth_path = params['auth_path']
# dst_path = params['dst_path']
# scp_path = params['scp_path']
# scp_name = params['scp_name']
EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
GetWindowText = ctypes.windll.user32.GetWindowTextW
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
IsWindowVisible = ctypes.windll.user32.IsWindowVisible
# Form1.SetFocus()
# if mode == 0:
# data_type = 'filename (from)'
# elif mode == 1:
# data_type = 'filename (to)'
# elif mode == 2:
# data_type = 'log'
# else:
# raise AssertionError('Invalid mode: {}'.format(mode))
# while True:
# k = input('Enter {}\n'.format(data_type))
# x, y = win32api.GetCursorPos()
# EnumWindows(EnumWindowsProc(foreach_window), 0)
titles = []
def foreach_window(hwnd, lParam):
if IsWindowVisible(hwnd):
length = GetWindowTextLength(hwnd)
buff = ctypes.create_unicode_buffer(length + 1)
GetWindowText(hwnd, buff, length + 1)
titles.append((hwnd, buff.value))
return True
win32gui.EnumWindows(foreach_window, None)
# for i in range(len(titles)):
# print(titles[i])
target_title = [k[1] for k in titles if win_title in k[1]]
print('target_title: {}'.format(target_title))
if not target_title:
print('Window with win_title: {} not found'.format(win_title))
return
target_title = target_title[0]
# print('target_title: {}'.format(target_title))
try:
app = application.Application().connect(title=target_title, found_index=0)
except BaseException as e:
print('Failed to connect to app for window {}: {}'.format(target_title, e))
return
try:
app_win = app.window(title=target_title)
except BaseException as e:
print('Failed to access app window for {}: {}'.format(target_title, e))
return
app_win.type_keys("^Q")
if app_win.exists():
dialogs = app.windows()
print(dialogs)
diag_win = app.window(handle=dialogs[0])
# print(diag_win)
diag_win.type_keys("~")
if __name__ == '__main__':
main()