Browse Source

Merge pull request #116 from Xenoamor/master

Add MOUSE_BACK and MOUSE_FORWARD to usb_mouse
main
Paul Stoffregen 8 years ago
parent
commit
725a89ec7d
3 changed files with 14 additions and 8 deletions
  1. +2
    -0
      keywords.txt
  2. +6
    -4
      teensy3/usb_mouse.c
  3. +6
    -4
      teensy3/usb_mouse.h

+ 2
- 0
keywords.txt View File

MOUSE_MIDDLE LITERAL1 MOUSE_MIDDLE LITERAL1
MOUSE_RIGHT LITERAL1 MOUSE_RIGHT LITERAL1
MOUSE_ALL LITERAL1 MOUSE_ALL LITERAL1
MOUSE_BACK LITERAL1
MOUSE_FORWARD LITERAL1


# USB Joystick # USB Joystick
Joystick KEYWORD1 Joystick KEYWORD1

+ 6
- 4
teensy3/usb_mouse.c View File



// Set the mouse buttons. To create a "click", 2 calls are needed, // Set the mouse buttons. To create a "click", 2 calls are needed,
// one to push the button down and the second to release it // one to push the button down and the second to release it
int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right)
int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back, uint8_t forward)
{ {
uint8_t mask=0; uint8_t mask=0;


if (left) mask |= 1;
if (middle) mask |= 4;
if (right) mask |= 2;
if (left) mask |= 1;
if (middle) mask |= 4;
if (right) mask |= 2;
if (back) mask |= 8;
if (forward) mask |= 16;
usb_mouse_buttons_state = mask; usb_mouse_buttons_state = mask;
return usb_mouse_move(0, 0, 0); return usb_mouse_move(0, 0, 0);
} }

+ 6
- 4
teensy3/usb_mouse.h View File

#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right);
int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back, uint8_t forward);
int usb_mouse_move(int8_t x, int8_t y, int8_t wheel); int usb_mouse_move(int8_t x, int8_t y, int8_t wheel);
int usb_mouse_position(uint16_t x, uint16_t y); int usb_mouse_position(uint16_t x, uint16_t y);
void usb_mouse_screen_size(uint16_t width, uint16_t height, uint8_t mac); void usb_mouse_screen_size(uint16_t width, uint16_t height, uint8_t mac);
#define MOUSE_LEFT 1 #define MOUSE_LEFT 1
#define MOUSE_MIDDLE 4 #define MOUSE_MIDDLE 4
#define MOUSE_RIGHT 2 #define MOUSE_RIGHT 2
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
#define MOUSE_BACK 8
#define MOUSE_FORWARD 16
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_BACK | MOUSE_FORWARD)


// C++ interface // C++ interface
#ifdef __cplusplus #ifdef __cplusplus
usb_mouse_move(0, 0, 0); usb_mouse_move(0, 0, 0);
} }
void scroll(int8_t wheel) { usb_mouse_move(0, 0, wheel); } void scroll(int8_t wheel) { usb_mouse_move(0, 0, wheel); }
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0) {
usb_mouse_buttons(left, middle, right);
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0, uint8_t back=0, uint8_t forward=0) {
usb_mouse_buttons(left, middle, right, back, forward);
} }
void press(uint8_t b = MOUSE_LEFT) { void press(uint8_t b = MOUSE_LEFT) {
uint8_t buttons = usb_mouse_buttons_state | (b & MOUSE_ALL); uint8_t buttons = usb_mouse_buttons_state | (b & MOUSE_ALL);

Loading…
Cancel
Save