_input.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from typing import Callable
  2. INPUT_BUTTON_UP: int
  3. '''
  4. Constant value for the `up` button.
  5. '''
  6. INPUT_BUTTON_DOWN: int
  7. '''
  8. Constant value for the `down` button.
  9. '''
  10. INPUT_BUTTON_RIGHT: int
  11. '''
  12. Constant value for the `right` button.
  13. '''
  14. INPUT_BUTTON_LEFT: int
  15. '''
  16. Constant value for the `left` button.
  17. '''
  18. INPUT_BUTTON_OK: int
  19. '''
  20. Constant value for the `ok` button.
  21. '''
  22. INPUT_BUTTON_BACK: int
  23. '''
  24. Constant value for the `back` button.
  25. '''
  26. INPUT_TYPE_PRESS: int
  27. '''
  28. Constant value for the `press` event of a button.
  29. '''
  30. INPUT_TYPE_RELEASE: int
  31. '''
  32. Constant value for the `release` event of a button.
  33. '''
  34. INPUT_TYPE_SHORT: int
  35. '''
  36. Constant value for the `short` press event of a button.
  37. '''
  38. INPUT_TYPE_LONG: int
  39. '''
  40. Constant value for the `long` press event of a button.
  41. '''
  42. INPUT_TYPE_REPEAT: int
  43. '''
  44. Constant value for the `repeat` press event of a button.
  45. '''
  46. def on_input() -> Callable[[int, int], None]:
  47. '''
  48. 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.
  49. .. code-block::
  50. import flipperzero as f0
  51. @f0.on_input
  52. def input_handler(button, type):
  53. if button == f0.INPUT_BUTTON_BACK:
  54. if type == f0.INPUT_TYPE_LONG:
  55. ...
  56. .. warning::
  57. You can only decorate one function per application.
  58. '''
  59. pass