Last active
March 16, 2022 07:12
-
-
Save jcwillox/644968ce3e5914b10387001144250297 to your computer and use it in GitHub Desktop.
Simple Python script to rapidly press a set of keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from string import digits | |
from time import sleep | |
import pydirectinput | |
import win32api | |
import win32con | |
parser = argparse.ArgumentParser(description="Repeatedly press keyboard keys") | |
parser.add_argument("key", nargs="*", default=list(digits)) | |
parser.add_argument( | |
"-d", | |
"--delay", | |
metavar="secs", | |
default=0.1, | |
type=float, | |
help="delay between pressing key set", | |
) | |
parser.add_argument( | |
"-i", | |
"--inter-key-delay", | |
metavar="secs", | |
default=0.01, | |
type=float, | |
help="delay between pressing individual keys", | |
) | |
args = parser.parse_args() | |
pydirectinput.PAUSE = 0 | |
enabled = None | |
print(f"\x1b[1;94mKEYS\x1b[0;94m:\x1b[0;96m {','.join(args.key)}") | |
try: | |
while True: | |
if enabled: | |
for key in args.key: | |
pydirectinput.press(key) | |
sleep(args.inter_key_delay) | |
caps_on = win32api.GetKeyState(win32con.VK_CAPITAL) == 1 | |
if caps_on is not enabled: | |
enabled = caps_on | |
if enabled: | |
print("\r\x1b[K\x1b[1;92mEnabled\x1b[0m", end="") | |
else: | |
print("\r\x1b[1;91mDisabled\x1b[0m", end="") | |
sleep(args.delay) | |
except KeyboardInterrupt: | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Originally created to automatically activate BTD6 abilities. Use CAPSLOCK to toggle the enabled state.