-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathcore.py
100 lines (89 loc) · 3.61 KB
/
core.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
import win32gui
import yaml
import platform
global hwnd
hwnd = 0
with open("pybot-config.yaml", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
def findWindow_Linux(data):
import subprocess
subprocess.call(["xdotool", "search", "--name", data, "windowfocus", "%2"])
subprocess.call(["xdotool", "getwindowfocus", "windowmove", "0", "0"])
subprocess.call(["xdotool", "getwindowfocus", "windowsize", "865", "830"])
def getWindow_Linux(data):
import subprocess
subprocess.call(["xdotool", "search", "--name", data, "windowfocus", "%2"])
rect = subprocess.call(["xdotool", "getwindowfocus", "getwindowgeometry"])
# Take care of borders for finding character
x = rect[0]
# 30 is the amount of pixels in the client top border
y = rect[1] + 30
# 50 is the amount of pixels in the client side border
w = rect[2] - x - 50
h = rect[3] - y - 30
# Find center
#print('window width:', w, 'window height:', h)
return x, y, w, h
def findWindow_runelite(): # find window name returns PID of the window
global hwnd
hwnd = win32gui.FindWindow(None, "RuneLite")
# hwnd = win32gui.GetForegroundWindow()860
#print('findWindow:', hwnd)
win32gui.SetActiveWindow(hwnd)
# win32gui.ShowWindow(hwnd)
win32gui.MoveWindow(hwnd, 0, 0, 865, 830, True)
def findWindow_openosrs(): # find window name returns PID of the window
global hwnd
hwnd = win32gui.FindWindow(None, "OpenOSRS")
# hwnd = win32gui.GetForegroundWindow()860
#print('findWindow:', hwnd)
win32gui.SetActiveWindow(hwnd)
# win32gui.ShowWindow(hwnd)
win32gui.MoveWindow(hwnd, 0, 0, 865, 830, True)
def findWindow(data): # find window name returns PID of the window
global hwnd
hwnd = win32gui.FindWindow(None, data)
# hwnd = win32gui.GetForegroundWindow()860
#print('findWindow:', hwnd)
win32gui.SetActiveWindow(hwnd)
# win32gui.ShowWindow(hwnd)
win32gui.MoveWindow(hwnd, 0, 0, 865, 830, True)
def getWindow(data): # find window name returns PID of the window
global hwnd
hwnd = win32gui.FindWindow(None, data)
# hwnd = win32gui.GetForegroundWindow()860
#print('findWindow:', hwnd)
win32gui.SetActiveWindow(hwnd)
win32gui.SetForegroundWindow(hwnd)
rect = win32gui.GetWindowRect(hwnd)
# Take care of borders for finding character
x = rect[0]
# 30 is the amount of pixels in the client top border
y = rect[1] + 30
# 50 is the amount of pixels in the client side border
w = rect[2] - x - 50
h = rect[3] - y - 30
# Find center
#print('window width:', w, 'window height:', h)
return x, y, w, h
def printWindows():
def winEnumHandler(hwnd, ctx):
if win32gui.IsWindowVisible(hwnd):
if win32gui.GetWindowText(hwnd) is not None and win32gui.GetWindowText(hwnd) != '':
print(win32gui.GetWindowText(hwnd))
win32gui.EnumWindows(winEnumHandler, None)
print('Operating system:', platform.system())
if platform.system() == 'Linux' or platform.system() == 'Mac':
try:
findWindow_Linux(data[0]['Config']['client_title'])
except BaseException:
print("unable to find window:", data[0]['Config']['client_title'], "please see list of window names below:")
printWindows()
pass
else:
try:
findWindow(data[0]['Config']['client_title'])
except BaseException:
print("Unable to find window:", data[0]['Config']['client_title'], "| Please see list of window names below:")
printWindows()
pass