-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindowshandlecorrection.py
More file actions
78 lines (56 loc) · 2.21 KB
/
windowshandlecorrection.py
File metadata and controls
78 lines (56 loc) · 2.21 KB
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
import pygetwindow as gw
import win32process
import win32api
import win32con
# print(gw.getAllTitles())
# print(gw.getAllWindows())
print(gw.getWindowsWithTitle('WhatsApp'))
# print("active window", gw.getActiveWindow())
# print("active window title", gw.getActiveWindow().title)
# print("selected handle is =", gw.getWindowsWithTitle('PyGetWindow'))
# app = gw.getWindowsWithTitle('PyG')[0]
# app.maximize()
def processname_from_handle(hwnd):
pid = win32process.GetWindowThreadProcessId(hwnd)
handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_VM_READ, False, pid[1])
proc_name_path = win32process.GetModuleFileNameEx(handle, 0)
proc_name = proc_name = proc_name_path.rsplit("\\", 1)[1]
'''print("procname with path", proc_name_path)
print("procname from handle (removing the path)", proc_name)'''
return proc_name
def compatibility(input):
modstring = str(input).replace("[Win32Window(hWnd=", "")
modstring2 = modstring.replace(")]", "")
print(modstring2)
return(modstring2)
print(processname_from_handle(gw.getWindowsWithTitle('WhatsApp')))
processname_from_handle(131942)
def restorewindow(processname):
windowname = processname.split(".")[0]
# print("selected handle is =", gw.getWindowsWithTitle(windowname))
windowhandle = gw.getWindowsWithTitle(windowname)[0]
# print(windowhandle.isMaximized)
if windowhandle.isMaximized is True:
windowhandle.activate()
else:
windowhandle.maximize()
def minimizewindow(processname):
windowname = processname.split(".")[0]
# print("selected handle is =", gw.getWindowsWithTitle(windowname))
windowhandle = gw.getWindowsWithTitle(windowname)[0]
# print(windowhandle.isMaximized)
windowhandle.minimize()
'''minimizewindow("Sekiro.exe")
restorewindow("Sekiro.exe")'''
'''windowtitle_path = gw.getActiveWindow().title
if "\\" in windowtitle_path:
windowtitle = windowtitle_path.rsplit("\\", 1)[1]
if ".exe" in windowtitle:
windowname = windowtitle.replace(".exe", "")
else:
windowname = windowtitle
elif ".exe" in windowtitle_path:
windowtitle_path.replace(".exe", "")
else:
windowname = windowtitle_path
print(windowname)'''