Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

103 lines
3.4KB

  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2013 PJRC.COM, LLC.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * 1. The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * 2. If the Software is incorporated into a build system that allows
  17. * selection among a list of target devices, then similar target
  18. * devices manufactured by PJRC.COM must be included in the list of
  19. * target devices and selectable in the same manner.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  25. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  26. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  27. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. * SOFTWARE.
  29. */
  30. #ifndef USBmouse_h_
  31. #define USBmouse_h_
  32. #if defined(USB_HID) || defined(USB_SERIAL_HID)
  33. #include <inttypes.h>
  34. // C language implementation
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right);
  39. int usb_mouse_move(int8_t x, int8_t y, int8_t wheel);
  40. int usb_mouse_position(uint16_t x, uint16_t y);
  41. void usb_mouse_screen_size(uint16_t width, uint16_t height, uint8_t mac);
  42. extern uint8_t usb_mouse_buttons_state;
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. #define MOUSE_LEFT 1
  47. #define MOUSE_MIDDLE 4
  48. #define MOUSE_RIGHT 2
  49. #define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
  50. // C++ interface
  51. #ifdef __cplusplus
  52. class usb_mouse_class
  53. {
  54. public:
  55. void begin(void) { }
  56. void end(void) { }
  57. void move(int8_t x, int8_t y, int8_t wheel=0) { usb_mouse_move(x, y, wheel); }
  58. void moveTo(uint16_t x, uint16_t y) { usb_mouse_position(x, y); }
  59. void screenSize(uint16_t width, uint16_t height, bool isMacintosh = false) {
  60. usb_mouse_screen_size(width, height, isMacintosh ? 1 : 0);
  61. }
  62. void click(uint8_t b = MOUSE_LEFT) {
  63. usb_mouse_buttons_state = b;
  64. usb_mouse_move(0, 0, 0);
  65. usb_mouse_buttons_state = 0;
  66. usb_mouse_move(0, 0, 0);
  67. }
  68. void scroll(int8_t wheel) { usb_mouse_move(0, 0, wheel); }
  69. void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0) {
  70. usb_mouse_buttons(left, middle, right);
  71. }
  72. void press(uint8_t b = MOUSE_LEFT) {
  73. uint8_t buttons = usb_mouse_buttons_state | (b & MOUSE_ALL);
  74. if (buttons != usb_mouse_buttons_state) {
  75. usb_mouse_buttons_state = buttons;
  76. usb_mouse_move(0, 0, 0);
  77. }
  78. }
  79. void release(uint8_t b = MOUSE_LEFT) {
  80. uint8_t buttons = usb_mouse_buttons_state & ~(b & MOUSE_ALL);
  81. if (buttons != usb_mouse_buttons_state) {
  82. usb_mouse_buttons_state = buttons;
  83. usb_mouse_move(0, 0, 0);
  84. }
  85. }
  86. bool isPressed(uint8_t b = MOUSE_ALL) {
  87. return ((usb_mouse_buttons_state & (b & MOUSE_ALL)) != 0);
  88. }
  89. };
  90. extern usb_mouse_class Mouse;
  91. #endif // __cplusplus
  92. #endif // USB_HID || USB_SERIAL_HID
  93. #endif // USBmouse_h_