vlatkovski

tricky-towers.py

Aug 29th, 2017
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. """read the first and only argument of the first function called in the function main -- wait what"""
  2. #pylint: disable=E0611, C0413, C0103
  3. import sys
  4. sys.path.append('d:\\vlatko\\Programming\\Code\\Python')
  5. import time
  6. from inpututil import inpututil # https://github.com/vlatkosh/inpututil
  7. import pyautogui
  8.  
  9. def format_func_info(func, show_address=False):
  10.     """read the name"""
  11.     import re
  12.     result = re.match(r'<function ([\w._]+) at (0x[0-9A-F]+)>', str(func))
  13.     if result is None:
  14.         return "<COULDN'T FORMAT>"
  15.     return result.group(1) + (f"<{result.group(2)}>" if show_address else "")
  16.  
  17. def exit_app():
  18.     """read the name"""
  19.     import os
  20.     os.kill(os.getpid(), 9)
  21.  
  22. def quick_restart():
  23.     """read the name"""
  24.     for t, k in [(0, 'esc'), (0.35, 'down'), (0.15, 'enter')]:
  25.         time.sleep(t)
  26.         pyautogui.press(k)
  27.  
  28. def press(*args):
  29.     """read the name"""
  30.     pyautogui.press(args)
  31.     print("sent", args)
  32.  
  33. def main():
  34.     # pylint: disable=C0326
  35.     """main function"""
  36.     print("*** Tricky Towers 'Quality[?]-of-life' program by vlatko[sh].***")
  37.  
  38.     iu = inpututil.InputUtil()
  39.     iu.bind_pause_hotkey(inpututil.VK['DELETE'])
  40.     iu.bind_hotkey(keys=inpututil.VK['NEXT'],     timeout=0,    func=exit_app)
  41.     iu.bind_hotkey(keys=inpututil.VK['END'],      timeout=1,    func=quick_restart)
  42.     iu.bind_hotkey(keys=inpututil.VK['RCONTROL'],               func=press,         args=['a'])
  43.     iu.bind_hotkey(keys=inpututil.VK['NUMPAD0'],                func=press,         args=['d'])
  44.     iu.bind_hotkey(keys=inpututil.VK['UP'],       timeout=0.08, func=press,         args=['w'])
  45.     iu.bind_hotkey(keys=inpututil.VK['KEY_E'],    timeout=0.08, func=press,         args=['w'])
  46.     iu.start()
  47.  
  48. if __name__ == "__main__":
  49.     main()
Advertisement
Add Comment
Please, Sign In to add comment