-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (65 loc) · 2.03 KB
/
Copy pathmain.py
File metadata and controls
72 lines (65 loc) · 2.03 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
# https://www.donttap.com/
# https://kizi.com/games/magic-piano-tiles
import pyautogui as pag
import keyboard
from time import sleep
from os import system
XY = []
COLOR = (0,0,0) # Black
TOLERANCE = 50
# write XY to coordinates.txt
def write_coordinates():
with open('coordinates.txt','w') as cord:
for pos in XY:
cord.write(f"{int(pos[0])}, {int(pos[1])}\n")
cord.close()
# Read coordinates.txt and update XY list
def read_coordinates():
global XY
XY.clear()
with open('coordinates.txt','r') as cord:
for pos in cord.readlines():
pos = pos.split(',')
XY.append([int(pos[0]), int(pos[1])])
cord.close()
#
def capture_coordinates(mode='new'):
global XY
if mode=='new':
XY.clear()
while True:
if keyboard.is_pressed('e'):
X, Y = pag.position()
print("Added : x,y = ", X, Y)
XY.append([X, Y])
sleep(0.25)
elif keyboard.is_pressed('q'):
break
write_coordinates()
def start():
while True:
for i in range(len(XY)):
if keyboard.is_pressed('q'):
return
elif pag.pixelMatchesColor(XY[i][0], XY[i][1], COLOR, tolerance=TOLERANCE):
pag.click(XY[i][0], XY[i][1], button='left', clicks=1)
print(f"Press 'q' to stop | x = {XY[i][0]} | y = {XY[i][1]}")
read_coordinates()
while True:
system('cls')
print("coordinates: ",XY)
print("\n1) New coordinates\n2) Insert coordinates\n3) Start\n0) Exit")
choice = input(":")
if choice == '1':
print("\nPlace cursur on the piano tile and press 'e' to insert coordinate\npress 'q' when you done\n")
capture_coordinates()
elif choice == '2':
print("\nPlace cursur on the piano tile and press 'e' to insert coordinate\npress 'q' when you done\n")
capture_coordinates(mode='insert')
elif choice == '3':
print("Press 'q' to stop")
start()
elif choice == '0':
break
else:
continue