-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoolkit_windows.py
More file actions
35 lines (26 loc) · 876 Bytes
/
toolkit_windows.py
File metadata and controls
35 lines (26 loc) · 876 Bytes
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
import win32api
import win32gui
import win32con
import time
import cv2
from PIL import ImageGrab
import logging
WINDOW_TITLE = "Chrome"
# Get the coordinate of the window (up left)
def getGameWindowPosition(WINDOW_TITLE):
# FindWindow(lpClassName=None, lpWindowName=None)
window = win32gui.FindWindow(None, WINDOW_TITLE)
while not window:
logging.info('Failed to navigate the windows, wait 5s...')
time.sleep(5)
window = win32gui.FindWindow(None, WINDOW_TITLE)
win32gui.SetForegroundWindow(window) # Put the window to the top
pos = win32gui.GetWindowRect(window)
logging.info("Got window" + str(pos))
return (pos[0], pos[1])
def getScreenImage():
scim = ImageGrab.grab()
scim.save('./screen.png')
return cv2.imread("./screen.png")
if __name__ == '__main__':
pass