-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapps.py
More file actions
101 lines (80 loc) · 2.92 KB
/
Copy pathopenapps.py
File metadata and controls
101 lines (80 loc) · 2.92 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import pyautogui
import cv2
import numpy as np
import time
import random
#im read converts the image into a numpy array
FOX_LOGO = cv2.imread("resources/FireFoxLogo.png")
FOX_SEARCH = cv2.imread("resources/FireFoxSearchBar.png")
OBS_LOGO = cv2.imread("resources/obsLogo.png")
OBS_SRECORD = cv2.imread("resources/obsStopRecording.png")
SCREEN_WIDTH, SCREEN_HEIGHT = pyautogui.size()
CENTER_X = SCREEN_WIDTH // 2
CENTER_Y = SCREEN_HEIGHT // 2
def mouse_center():
pyautogui.moveTo(CENTER_X, CENTER_Y)
def clickImage(inputImg):
img = pyautogui.screenshot()
img_np = np.array(img)
main_image = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
if inputImg is None:
print("Error: Template image not found!")
exit()
gray_main = cv2.cvtColor(main_image, cv2.COLOR_BGR2GRAY)
gray_template = cv2.cvtColor(inputImg, cv2.COLOR_BGR2GRAY)
result = cv2.matchTemplate(gray_main, gray_template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
h, w = gray_template.shape
screen_w, screen_h = pyautogui.size()
image_h, image_w = main_image.shape[:2]
scale_x = screen_w / image_w
scale_y = screen_h / image_h
center_x = int((max_loc[0] + w // 2) * scale_x)
center_y = int((max_loc[1] + h // 2) * scale_y)
pyautogui.moveTo(center_x, center_y, duration=0.5)
pyautogui.click()
time.sleep(3)
def detect_video_region(adjustX=0, adjustY=0):
prev_frame = np.array(pyautogui.screenshot())
prev_gray = cv2.cvtColor(prev_frame, cv2.COLOR_RGB2GRAY)
time.sleep(0.2)
for _ in range(30):
curr_frame = np.array(pyautogui.screenshot())
curr_gray = cv2.cvtColor(curr_frame, cv2.COLOR_RGB2GRAY)
diff = cv2.absdiff(prev_gray, curr_gray)
_, thresh = cv2.threshold(diff, 40, 255, cv2.THRESH_BINARY)
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
if contours:
x, y, w, h = cv2.boundingRect(max(contours, key=cv2.contourArea))
return (x + adjustX, y + adjustY, w, h)
prev_gray = curr_gray
time.sleep(0.1)
return None
def open_tiktok():
clickImage(FOX_LOGO)
clickImage(FOX_SEARCH)
pyautogui.write("https://www.tiktok.com/foryou ", interval=0.2)
pyautogui.press('enter')
time.sleep(6)
pyautogui.moveTo(CENTER_X, CENTER_Y)
pyautogui.click()
pyautogui.press('space')
def open_obs():
clickImage(OBS_LOGO)
def stop_recording():
clickImage(OBS_SRECORD)
def open_firefox():
clickImage(FOX_LOGO)
def close_app():
time.sleep(4)
pyautogui.keyDown('command') # Press the Command key
pyautogui.press('q') # Press the Q key
pyautogui.keyUp('command')
def open_inspect():
time.sleep(4)
pyautogui.keyDown('ctrl')
pyautogui.keyDown('shift')
pyautogui.press('C')
pyautogui.keyUp('ctrl')
pyautogui.keyUp('shift')
pyautogui.moveTo(CENTER_X, CENTER_Y)