_cli.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. rescriptoon
  3. Copyright (C) 2018-2019 Fabian Peter Hammerle <fabian@hammerle.me>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. """
  15. import argparse
  16. import logging
  17. from Xlib import X, XK
  18. import rescriptoon
  19. _DEFAULT_TOGGLE_KEYSYM_NAME = "grave"
  20. def main() -> None:
  21. logging.basicConfig(
  22. level=logging.DEBUG,
  23. format="%(asctime)s %(levelname)s: %(message)s",
  24. datefmt="%H:%I:%S",
  25. )
  26. argparser = argparse.ArgumentParser(
  27. description="Attach resriptoon to running Toontown Rewritten engines.",
  28. )
  29. argparser.add_argument(
  30. "--toggle",
  31. "-t",
  32. metavar="KEYSYM_NAME",
  33. dest="toggle_keysym_name",
  34. default=_DEFAULT_TOGGLE_KEYSYM_NAME,
  35. help="key to turn extended keyboard controls on / off."
  36. + " any keysym name may be used"
  37. + " (see XStringToKeysym & X11/keysymdef.h, "
  38. + " default: %(default)s)",
  39. )
  40. args = argparser.parse_args()
  41. toggle_keysym = XK.string_to_keysym(args.toggle_keysym_name)
  42. if toggle_keysym == X.NoSymbol:
  43. raise ValueError(
  44. "controls toggle: unknown keysym name '{}'".format(args.toggle_keysym_name)
  45. )
  46. rescriptoon.Overlay(toggle_keysym=toggle_keysym).run()