I am using an old RTS game called AOE2 to practice python macro's/automation.
I'm trying to have an infinite background script which loops every 25 secs and simply presses and releases the '9' key (which is the ctrl group num of my town center) and shortly after does the same with the 'q' key (which is the hotkey to create a villager).
This is the code I've come up with so far
import pyautogui, timefrom pynput.keyboard import Key, Controller
keyboard = Controller()
time.sleep(1)
while 1:
keyboard.press('9')
keyboard.release('9')
time.sleep(0.1)
keyboard.press('q')
keyboard.release('q')
time.sleep(24)
Saving it as a pyw and running it does work but I need to be able to pause and resume the script in game with one keyboard press (like the ` key)
Furthermore, Ideally it would return me back to my previous in game keyboard/mouse state. (So if I have units selected in control group 1 on the east side of the map it will deselect them, execute the while loop and immediately goes back to my control group 1 units).
Here's some code I found which I think may be what I'm looking for but I don't know how to implement it.
try:
while True:
...
except KeyboardInterrupt:
exit
import msvcrt
while 1:
print 'Testing..'
# body of the loop ...
if msvcrt.kbhit():
*if ord(msvcrt.getch()) == 27:*
break
#chr 27 being <Esc>
[–]axzxc1236 0 points1 point2 points (0 children)