USER PASS
/
USBMouse_test
test
Fork of USBMouse by
USBMouse/USBMouse.cpp@1:eb68149218fd, 2010-04-07 (annotated)
- Committer:
- simon
- Date:
- Wed Apr 07 13:42:47 2010 +0000
- Revision:
- 1:eb68149218fd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 1:eb68149218fd | 1 | #include "USBMouse.h" |
simon | 1:eb68149218fd | 2 | |
simon | 1:eb68149218fd | 3 | USBMouse::USBMouse() { |
simon | 1:eb68149218fd | 4 | _buttons = 0; |
simon | 1:eb68149218fd | 5 | } |
simon | 1:eb68149218fd | 6 | |
simon | 1:eb68149218fd | 7 | void USBMouse::move(int x, int y) { |
simon | 1:eb68149218fd | 8 | while(x > 127) { |
simon | 1:eb68149218fd | 9 | mouse(127, 0, _buttons, 0); |
simon | 1:eb68149218fd | 10 | x = x - 127; |
simon | 1:eb68149218fd | 11 | } |
simon | 1:eb68149218fd | 12 | while(x < -128) { |
simon | 1:eb68149218fd | 13 | mouse(-128, 0, _buttons, 0); |
simon | 1:eb68149218fd | 14 | x = x + 128; |
simon | 1:eb68149218fd | 15 | } |
simon | 1:eb68149218fd | 16 | while(y > 127) { |
simon | 1:eb68149218fd | 17 | mouse(0, 127, _buttons, 0); |
simon | 1:eb68149218fd | 18 | y = y - 127; |
simon | 1:eb68149218fd | 19 | } |
simon | 1:eb68149218fd | 20 | while(y < -128) { |
simon | 1:eb68149218fd | 21 | mouse(0, -128, _buttons, 0); |
simon | 1:eb68149218fd | 22 | y = y + 128; |
simon | 1:eb68149218fd | 23 | } |
simon | 1:eb68149218fd | 24 | mouse(x, y, _buttons, 0); |
simon | 1:eb68149218fd | 25 | } |
simon | 1:eb68149218fd | 26 | |
simon | 1:eb68149218fd | 27 | void USBMouse::scroll(int z) { |
simon | 1:eb68149218fd | 28 | while(z > 127) { |
simon | 1:eb68149218fd | 29 | mouse(0, 0, _buttons, 127); |
simon | 1:eb68149218fd | 30 | z = z - 127; |
simon | 1:eb68149218fd | 31 | } |
simon | 1:eb68149218fd | 32 | while(z < -128) { |
simon | 1:eb68149218fd | 33 | mouse(0, 0, _buttons, -128); |
simon | 1:eb68149218fd | 34 | z = z + 128; |
simon | 1:eb68149218fd | 35 | } |
simon | 1:eb68149218fd | 36 | mouse(0, 0, _buttons, z); |
simon | 1:eb68149218fd | 37 | } |
simon | 1:eb68149218fd | 38 | |
simon | 1:eb68149218fd | 39 | void USBMouse::buttons(int left, int middle, int right) { |
simon | 1:eb68149218fd | 40 | int _buttons = 0; |
simon | 1:eb68149218fd | 41 | if(left) { |
simon | 1:eb68149218fd | 42 | _buttons |= MOUSE_L; |
simon | 1:eb68149218fd | 43 | } |
simon | 1:eb68149218fd | 44 | if(middle) { |
simon | 1:eb68149218fd | 45 | _buttons |= MOUSE_M; |
simon | 1:eb68149218fd | 46 | } |
simon | 1:eb68149218fd | 47 | if(right) { |
simon | 1:eb68149218fd | 48 | _buttons |= MOUSE_R; |
simon | 1:eb68149218fd | 49 | } |
simon | 1:eb68149218fd | 50 | mouse(0,0, _buttons, 0); |
simon | 1:eb68149218fd | 51 | } |