tooncher-extend-controls 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. # PYTHON_ARGCOMPLETE_OK
  3. import os
  4. import sys
  5. import tooncher.controls
  6. def run(engine_pid,
  7. toggle_keysym_name=tooncher.controls.EXTENDED_CONTROLS_DEFAULT_TOGGLE_KEYSYM_NAME):
  8. ec = tooncher.controls.ExtendedControls(
  9. engine_pid=engine_pid,
  10. toggle_keysym_name=toggle_keysym_name,
  11. )
  12. ec.run()
  13. def _init_argparser():
  14. import argparse
  15. argparser = argparse.ArgumentParser(
  16. description="Attach Extended Controls to an already running Toontown engine.",
  17. )
  18. argparser.add_argument(
  19. 'engine_pid',
  20. type=int,
  21. help="process id",
  22. )
  23. argparser.add_argument(
  24. '--toggle', '-t',
  25. metavar='KEYSYM_NAME',
  26. dest='toggle_keysym_name',
  27. default=tooncher.controls.EXTENDED_CONTROLS_DEFAULT_TOGGLE_KEYSYM_NAME,
  28. help='key to turn extended keyboard controls on / off.'
  29. + ' any keysym name may be used'
  30. + ' (see XStringToKeysym & X11/keysymdef.h, '
  31. + ' default: %(default)s)',
  32. )
  33. return argparser
  34. def main(argv):
  35. argparser = _init_argparser()
  36. try:
  37. import argcomplete
  38. argcomplete.autocomplete(argparser)
  39. except ImportError:
  40. pass
  41. args = argparser.parse_args(argv)
  42. run(**vars(args))
  43. return 0
  44. if __name__ == "__main__":
  45. sys.exit(main(sys.argv[1:]))