_mapping.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import typing
  2. from Xlib import XK
  3. from rescriptoon._actions import LowThrowAction, RewriteKeyEventAction, SelectGagAction
  4. from rescriptoon._keys import USKeyCode
  5. _DEFAULT_KEYCODE_ACTION_MAPPING = {
  6. # pylint: disable=no-member; false positive for XK.*
  7. USKeyCode.w: RewriteKeyEventAction(keysym=XK.XK_Up, target_engine_index=0),
  8. USKeyCode.a: RewriteKeyEventAction(keysym=XK.XK_Left, target_engine_index=0),
  9. USKeyCode.s: RewriteKeyEventAction(keysym=XK.XK_Down, target_engine_index=0),
  10. USKeyCode.d: RewriteKeyEventAction(keysym=XK.XK_Right, target_engine_index=0),
  11. USKeyCode.ctrl_left: RewriteKeyEventAction(
  12. keysym=XK.XK_Control_L, target_engine_index=0
  13. ),
  14. USKeyCode.v: LowThrowAction(target_engine_index=0),
  15. USKeyCode.o: RewriteKeyEventAction(keysym=XK.XK_Up, target_engine_index=1),
  16. USKeyCode.k: RewriteKeyEventAction(keysym=XK.XK_Left, target_engine_index=1),
  17. USKeyCode.l: RewriteKeyEventAction(keysym=XK.XK_Down, target_engine_index=1),
  18. USKeyCode.semicolon: RewriteKeyEventAction(
  19. keysym=XK.XK_Right, target_engine_index=1
  20. ),
  21. USKeyCode.slash: RewriteKeyEventAction(
  22. keysym=XK.XK_Control_L, target_engine_index=1
  23. ),
  24. USKeyCode.n: LowThrowAction(target_engine_index=1),
  25. USKeyCode.space: RewriteKeyEventAction(keysym=XK.XK_Control_L),
  26. # TODO replace gag_name with enum
  27. USKeyCode.e: SelectGagAction(
  28. gag_name="elephant trunk",
  29. target_engine_index=0,
  30. column_index=4,
  31. factor_y=-0.047,
  32. ),
  33. USKeyCode.i: SelectGagAction(
  34. gag_name="elephant trunk",
  35. target_engine_index=1,
  36. column_index=4,
  37. factor_y=-0.047,
  38. ),
  39. USKeyCode.f: SelectGagAction(
  40. gag_name="foghorn", target_engine_index=0, column_index=5, factor_y=-0.047
  41. ),
  42. USKeyCode.j: SelectGagAction(
  43. gag_name="foghorn", target_engine_index=1, column_index=5, factor_y=-0.047
  44. ),
  45. }
  46. def get_keycode_action_mapping() -> typing.Dict:
  47. return {
  48. us_keycode.value: action
  49. for us_keycode, action in _DEFAULT_KEYCODE_ACTION_MAPPING.items()
  50. }