Spaces:
Running
Running
File size: 1,628 Bytes
d140f7d |
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 |
import pyautogui
from pynput import keyboard
import yaml
regions = [
"screen_top_left",
"screen_bot_right",
]
map_regions = [
"map_top_left",
"map_bot_right",
"confirm_button",
"kodiak",
"hobart",
]
next_round_button = "next_round_button"
coords = []
PRESS_KEY = "a"
def on_press(key):
try:
if key.char == PRESS_KEY:
x, y = pyautogui.position()
print(x, y)
coords.append([x, y])
return False
except AttributeError:
pass
def get_coords(players=1):
for region in regions:
print(f"Move the mouse to the {region} region and press 'a'.")
with keyboard.Listener(on_press=on_press) as keyboard_listener:
keyboard_listener.join(timeout=40)
for p in range(1, players+1):
for region in map_regions:
region = region + f"_{p}"
regions.append(region)
print(f"Move the mouse to the {region} region and press 'a'.")
with keyboard.Listener(on_press=on_press) as keyboard_listener:
keyboard_listener.join(timeout=40)
regions.append(next_round_button)
print(f"Move the mouse to the {next_round_button} region and press 'a'.")
with keyboard.Listener(on_press=on_press) as keyboard_listener:
keyboard_listener.join(timeout=40)
screen_regions = {reg: coord for reg, coord in zip(regions, coords)}
# save dict as a yaml file
with open("screen_regions.yaml", "w") as f:
yaml.dump(screen_regions, f)
return screen_regions
if __name__ == "__main__":
_ = get_coords(players=1)
|