Q: The simulation is not running after I ran the py script.
A: Start an Administrator Command Prompt, type the full path of the py script and press Enter. You will need to close the Administrator Command Prompt and repeat this step whenever the target game is restarted (after crashing?). If this cannot resolve your problem, please open an issue.
Platform: Windows
Python: 3.7
Description: Want to automate boring repeated actions? Here you can automate anything with ease.
PyMacro was deprecated due to compatability issues with pynput.
After a while, PyMacroV2 is introduced for replacement of PyMacro.
pip3 install -r requirements.txt
Basic keystrokes simulations:
KeyDown(key)
presseskey
KeyUp(key)
releaseskey
Intermediate mouse simulations:
KeyPress(key)
pressess and releaseskey
Note: Values of key
can be found at here.
Basic mouse simulations:
MoveMouse(dx, dy)
moves to (dx
,dy
) coordinate in terms of pixelsMouseLDown()
presses left click at current mouse positionMouseLUp()
releases left click at current mouse positionMouseRDown()
presses right click at current mouse positionMouseRUp()
releases right click at current mouse position
Intermediate mouse simulations:
MouseLPress(dx, dy)
presses and releases left click at (dx
,dy
) coordinate in terms of pixelsMouseLDrag(dx1, dy1, dx2, dy2)
uses left click to drag an object located at (dx1
,dy1
) to (dx2
,dy2
) in terms of pixelsMouseRPress(dx, dy)
presses and releases right click at (dx
,dy
) coordinate in terms of pixelsMouseRDrag(dx1, dy1, dx2, dy2)
uses right click to drag an object located at (dx1
,dy1
) to (dx2
,dy2
) in terms of pixels
MISC:
Key_(char)
is used for key translations, see the simple example for the usage.SwitchToWindow(title)
switches to the window with titletitle
Delay(sec)
delays or waits forsec
second(s)STATIC_DELAY
is used between basic simulations in intermediate simulations
Simple example:
from PyMacroV2 import *
STATIC_DELAY = 1/3
SwitchToWindow("Untitled - Notepad")
Delay(1)
KeyPress(Key_('N'))
KeyPress(Key_('I'))
KeyDown(Key.shift_l)
KeyPress(Key_('c'))
KeyPress(Key_('e'))
KeyUp(Key.shift_l)
Key binding macro example (refer to PyMacroV2_driver.py):
- In this part, macros are stored in each individual function:
# Your macros & normal py codes
_1 = {"x":680,"y":880}
def macro_1():
MouseLPress(_1["x"],_1["y"])
def macro_f1():
MouseLPress(_1["x"]*1.1,_1["y"]*1.1)
- In this part, keys are mapped and binded to the corresponding function:
# Map keys to the corresponding function
# Value of key at https://pynput.readthedocs.io/en/latest/keyboard.html#pynput.keyboard.Key
combination_to_function = {
frozenset([Key_('1')]): macro_1, # Pressing key "1" executes "macro_1"
frozenset([Key.f1]): macro_f1 # Pressing key "F1" executes "macro_f1"
}
- More example:
def macro_s1():
MouseLDrag(_1["x"],_1["y"],_1["x"]+100,_1["y"])
combination_to_function = {
frozenset([Key.shift_l, Key_('1')]): macro_s1 # Pressing key "1" and "left shift" executes "macro_s1"
}