|
| 1 | + |
| 2 | +// Copyright 2013 Dustin Bensing |
| 3 | + |
| 4 | +// This file is part of XInputSimulator. |
| 5 | + |
| 6 | +// XInputSimulator is free software: you can redistribute it and/or modify |
| 7 | +// it under the terms of the GNU Lesser Public License as published by |
| 8 | +// the Free Software Foundation, either version 3 of the License, or |
| 9 | +// any later version. |
| 10 | + |
| 11 | +// XInputSimulator is distributed in the hope that it will be useful, |
| 12 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +// GNU Lesser Public License for more details. |
| 15 | + |
| 16 | +// You should have received a copy of the GNU Lesser Public License |
| 17 | +// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +#ifdef _WIN32 |
| 20 | + |
| 21 | +#include "xinputsimularotimplwin.h" |
| 22 | +#include "notimplementedexception.h" |
| 23 | +#include <iostream> |
| 24 | + |
| 25 | +#include <Windows.h> |
| 26 | + |
| 27 | +#define MOUSEEVENTF_HWHEEL 0x01000 |
| 28 | + |
| 29 | +XInputSimularotImplWin::XInputSimularotImplWin() |
| 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 | + } |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +void XInputSimularotImplWin::mouseMoveTo(int x, int y) |
| 46 | +{ |
| 47 | + SetCursorPos(x, y); |
| 48 | + |
| 49 | + this->currentX = x; |
| 50 | + this->currentY = y; |
| 51 | +} |
| 52 | + |
| 53 | +void XInputSimularotImplWin::mouseMoveRelative(int x, int y) |
| 54 | +{ |
| 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; |
| 62 | +} |
| 63 | + |
| 64 | +//TODO use the button from parameter list |
| 65 | +void XInputSimularotImplWin::mouseDown(int button) |
| 66 | +{ |
| 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)); |
| 72 | +} |
| 73 | + |
| 74 | +//TODO use the button from parameter list |
| 75 | +void XInputSimularotImplWin::mouseUp(int button) |
| 76 | +{ |
| 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)); |
| 82 | +} |
| 83 | + |
| 84 | +//TODO use the button from parameter list |
| 85 | +void XInputSimularotImplWin::mouseClick(int button) |
| 86 | +{ |
| 87 | + this->mouseDown(button); |
| 88 | + //std::this_thread::sleep_for(std::chrono::milliseconds(1000)); |
| 89 | + this->mouseUp(button); |
| 90 | +} |
| 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 |
| 92 | +void XInputSimularotImplWin::mouseScrollX(int length) |
| 93 | +{ |
| 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 | + } |
| 113 | +} |
| 114 | + |
| 115 | +void XInputSimularotImplWin::mouseScrollY(int length) |
| 116 | +{ |
| 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 | + } |
| 136 | +} |
| 137 | + |
| 138 | +void XInputSimularotImplWin::keyDown(int key) |
| 139 | +{ |
| 140 | + throw NotImplementedException(); |
| 141 | +} |
| 142 | + |
| 143 | +void XInputSimularotImplWin::keyUp(int key) |
| 144 | +{ |
| 145 | + throw NotImplementedException(); |
| 146 | +} |
| 147 | + |
| 148 | +#endif //win |
0 commit comments