_input.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from typing import Callable
  2. INPUT_BUTTON_UP: int
  3. """
  4. Constant value for the `up` button.
  5. .. versionadded:: 1.0.0
  6. """
  7. INPUT_BUTTON_DOWN: int
  8. """
  9. Constant value for the `down` button.
  10. .. versionadded:: 1.0.0
  11. """
  12. INPUT_BUTTON_RIGHT: int
  13. """
  14. Constant value for the `right` button.
  15. .. versionadded:: 1.0.0
  16. """
  17. INPUT_BUTTON_LEFT: int
  18. """
  19. Constant value for the `left` button.
  20. .. versionadded:: 1.0.0
  21. """
  22. INPUT_BUTTON_OK: int
  23. """
  24. Constant value for the `ok` button.
  25. .. versionadded:: 1.0.0
  26. """
  27. INPUT_BUTTON_BACK: int
  28. """
  29. Constant value for the `back` button.
  30. .. versionadded:: 1.0.0
  31. """
  32. INPUT_TYPE_PRESS: int
  33. """
  34. Constant value for the `press` event of a button.
  35. .. versionadded:: 1.0.0
  36. """
  37. INPUT_TYPE_RELEASE: int
  38. """
  39. Constant value for the `release` event of a button.
  40. .. versionadded:: 1.0.0
  41. """
  42. INPUT_TYPE_SHORT: int
  43. """
  44. Constant value for the `short` press event of a button.
  45. .. versionadded:: 1.0.0
  46. """
  47. INPUT_TYPE_LONG: int
  48. """
  49. Constant value for the `long` press event of a button.
  50. .. versionadded:: 1.0.0
  51. """
  52. INPUT_TYPE_REPEAT: int
  53. """
  54. Constant value for the `repeat` press event of a button.
  55. .. versionadded:: 1.0.0
  56. """
  57. def on_input() -> Callable[[int, int], None]:
  58. """
  59. Decorate a function to be used as input handler. The decorated function will be invoked upon interaction with one of the buttons on the Flipper.
  60. .. versionadded:: 1.0.0
  61. .. code-block::
  62. import flipperzero as f0
  63. @f0.on_input
  64. def input_handler(button, type):
  65. if button == f0.INPUT_BUTTON_BACK:
  66. if type == f0.INPUT_TYPE_LONG:
  67. ...
  68. .. warning::
  69. You can only decorate one function per application.
  70. """
  71. pass