Код: Выделить всё
import pyautogui
import pydirectinput
import keyboard
import time
print("""
Welcome too...
____ _____ ____ __ __ __ _ __ __ __
| __ )_ _| _ \ / /_ | \/ | |/ / | \/ | __ _ ___ _ __ ___
| _ \ | | | | | | '_ \| |\/| | ' / | |\/| |/ _` |/ __| '__/ _ \
| |_) || | | |_| | (_) | | | | . \ | | | | (_| | (__| | | (_) |
|____/ |_| |____/ \___/|_| |_|_|\_\ |_| |_|\__,_|\___|_| \___/
By MMW Studios
""")
print("\nTo Begin, Get to the BTD6 Home screen.")
dart_monkey = "q"
boomerang_monkey = "w"
bomb_shooter = "e"
tack_shooter = "r"
ice_monkey = "t"
glue_gunner = "y"
sniper_monkey = "z"
submarine_monkey = "x"
buccaneer_monkey = "c"
ace_monkey = "v"
helicopter_monkey = "b"
mortar_monkey = "n"
dartling_gunner = "m"
wizard_monkey = "a"
super_monkey = "s"
ninja_monkey = "d"
alchemist = "f"
druid = "g"
mermonkey = "o"
banana_farm = "h"
spike_factory = "j"
monkey_village = "k"
engineer_monkey = "l"
beast_handler = "i"
hero = "u"
def click(position, clicks=1):
pyautogui.moveTo(position, duration=0.2)
time.sleep(0.2)
pyautogui.click(clicks=clicks, interval=0.2)
def summon_tower(monkey, position):
pydirectinput.press(monkey)
time.sleep(0.2)
pyautogui.moveTo(position, duration=0.2)
time.sleep(0.2)
pyautogui.click()
def upgrade_tower(position, upgrades):
pyautogui.moveTo(position, duration=0.2)
time.sleep(0.2)
pyautogui.click()
pydirectinput.press(",", presses=upgrades[0], interval=0.2)
pydirectinput.press(".", presses=upgrades[1], interval=0.2)
pydirectinput.press("/", presses=upgrades[2], interval=0.2)
print("Press the spacebar to begin")
keyboard.wait("space")
time.sleep(1)
#This is the while loop I want to break out of with a key press.
while True:
click((825, 925))
click((1350, 950))
click((1400, 550))
click((630, 400))
click((1300, 450))
time.sleep()
click((965, 750))
summon_tower(monkey_village, (1582, 673))
upgrade_tower((1582, 673), [2, 0, 2])
summon_tower(sniper_monkey, (1527, 595))
upgrade_tower((1527, 595), [0, 2, 4])
summon_tower(alchemist, (1603, 592))
upgrade_tower((1603, 592), [4, 2, 0])
click((1830, 1000), 2)
time.sleep(300)
click((960, 900))
click((725, 850))
Код: Выделить всё
while True:
if keyboard.is_pressed("a"):
break
Я тоже пробовал:
Код: Выделить всё
try:
while True:
do_somthing()
time.sleep(10)
except KeyboardInterrupt:
pass
Опять же, я ищу надежный способ выйти из цикла while с помощью нажатия клавиши вне терминала.
Подробнее здесь: https://stackoverflow.com/questions/790 ... e-terminal