|
22 | 22 | #include "notimplementedexception.h"
|
23 | 23 | #include <iostream>
|
24 | 24 |
|
| 25 | +#include <Windows.h> |
| 26 | + |
| 27 | +#define MOUSEEVENTF_HWHEEL 0x01000 |
| 28 | + |
25 | 29 | XInputSimularotImplWin::XInputSimularotImplWin()
|
26 | 30 | {
|
| 31 | + this->initCurrentMousePosition(); |
| 32 | +} |
| 33 | + |
| 34 | +void XInputSimularotImplWin::initCurrentMousePosition() |
| 35 | +{ |
| 36 | + POINT p; |
| 37 | + if (GetCursorPos(&p)) |
| 38 | + { |
| 39 | + this->currentX = p.x; |
| 40 | + this->currentY = p.y; |
| 41 | + } |
27 | 42 | }
|
28 | 43 |
|
29 | 44 |
|
30 | 45 | void XInputSimularotImplWin::mouseMoveTo(int x, int y)
|
31 | 46 | {
|
32 |
| - std::cout << "move the mouse!\n"; |
| 47 | + SetCursorPos(x, y); |
| 48 | + |
| 49 | + this->currentX = x; |
| 50 | + this->currentY = y; |
33 | 51 | }
|
34 | 52 |
|
35 | 53 | void XInputSimularotImplWin::mouseMoveRelative(int x, int y)
|
36 | 54 | {
|
37 |
| - throw NotImplementedException(); |
| 55 | + int newX = this->currentX + x; |
| 56 | + int newY = this->currentY + y; |
| 57 | + |
| 58 | + SetCursorPos(newX, newY); |
| 59 | + |
| 60 | + this->currentX = newX; |
| 61 | + this->currentY = newY; |
38 | 62 | }
|
39 | 63 |
|
| 64 | +//TODO use the button from parameter list |
40 | 65 | void XInputSimularotImplWin::mouseDown(int button)
|
41 | 66 | {
|
42 |
| - throw NotImplementedException(); |
| 67 | + INPUT in={0}; |
| 68 | + in.type = INPUT_MOUSE; |
| 69 | + in.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; |
| 70 | + SendInput(1,&in,sizeof(INPUT)); |
| 71 | + ZeroMemory(&in,sizeof(INPUT)); |
43 | 72 | }
|
44 | 73 |
|
| 74 | +//TODO use the button from parameter list |
45 | 75 | void XInputSimularotImplWin::mouseUp(int button)
|
46 | 76 | {
|
47 |
| - throw NotImplementedException(); |
48 |
| - |
| 77 | + INPUT in={0}; |
| 78 | + in.type = INPUT_MOUSE; |
| 79 | + in.mi.dwFlags = MOUSEEVENTF_LEFTUP; |
| 80 | + SendInput(1,&in,sizeof(INPUT)); |
| 81 | + ZeroMemory(&in,sizeof(INPUT)); |
49 | 82 | }
|
50 | 83 |
|
| 84 | +//TODO use the button from parameter list |
51 | 85 | void XInputSimularotImplWin::mouseClick(int button)
|
52 | 86 | {
|
53 |
| - throw NotImplementedException(); |
54 | 87 | this->mouseDown(button);
|
55 | 88 | //std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
56 | 89 | this->mouseUp(button);
|
57 | 90 | }
|
58 | 91 | //kajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjf
|
59 | 92 | void XInputSimularotImplWin::mouseScrollX(int length)
|
60 | 93 | {
|
61 |
| - throw NotImplementedException(); |
| 94 | + int scrollDirection = 1 * 50; // 1 left -1 right |
| 95 | + |
| 96 | + if(length < 0){ |
| 97 | + length *= -1; |
| 98 | + scrollDirection *= -1; |
| 99 | + } |
| 100 | + |
| 101 | + for(int cnt = 0; cnt < length; cnt++) |
| 102 | + { |
| 103 | + INPUT in; |
| 104 | + in.type = INPUT_MOUSE; |
| 105 | + in.mi.dx = 0; |
| 106 | + in.mi.dy = 0; |
| 107 | + in.mi.dwFlags = MOUSEEVENTF_HWHEEL; |
| 108 | + in.mi.time = 0; |
| 109 | + in.mi.dwExtraInfo = 0; |
| 110 | + in.mi.mouseData = scrollDirection;// WHEEL_DELTA; |
| 111 | + SendInput(1,&in,sizeof(in)); |
| 112 | + } |
62 | 113 | }
|
63 | 114 |
|
64 | 115 | void XInputSimularotImplWin::mouseScrollY(int length)
|
65 | 116 | {
|
66 |
| - throw NotImplementedException(); |
| 117 | + int scrollDirection = -1 * 50; // 1 up -1 down |
| 118 | + |
| 119 | + if(length < 0){ |
| 120 | + length *= -1; |
| 121 | + scrollDirection *= -1; |
| 122 | + } |
| 123 | + |
| 124 | + for(int cnt = 0; cnt < length; cnt++) |
| 125 | + { |
| 126 | + INPUT in; |
| 127 | + in.type = INPUT_MOUSE; |
| 128 | + in.mi.dx = 0; |
| 129 | + in.mi.dy = 0; |
| 130 | + in.mi.dwFlags = MOUSEEVENTF_WHEEL; |
| 131 | + in.mi.time = 0; |
| 132 | + in.mi.dwExtraInfo = 0; |
| 133 | + in.mi.mouseData = scrollDirection;// WHEEL_DELTA; |
| 134 | + SendInput(1,&in,sizeof(in)); |
| 135 | + } |
67 | 136 | }
|
68 | 137 |
|
69 | 138 | void XInputSimularotImplWin::keyDown(int key)
|
|
0 commit comments