Skip to content

Commit fd0dcf1

Browse files
committed
blah
1 parent 654d079 commit fd0dcf1

File tree

2 files changed

+199
-0
lines changed

2 files changed

+199
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2013 Dustin Bensing
2+
3+
// This file is part of XInputSimulator.
4+
5+
// XInputSimulator is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Lesser Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// any later version.
9+
10+
// XInputSimulator is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Lesser Public License for more details.
14+
15+
// You should have received a copy of the GNU Lesser Public License
16+
// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#ifdef _WIN32
19+
20+
#ifndef XINPUTSIMULAROTIMPLWIN_H
21+
#define XINPUTSIMULAROTIMPLWIN_H
22+
23+
#include "xinputsimulatorimpl.h"
24+
25+
class XInputSimularotImplWin: public XInputSimulatorImpl
26+
{
27+
private:
28+
int currentX;
29+
int currentY;
30+
31+
void initCurrentMousePosition();
32+
33+
public:
34+
XInputSimularotImplWin();
35+
~XInputSimularotImplWin(){}
36+
37+
virtual void mouseMoveTo(int x, int y) override;
38+
virtual void mouseMoveRelative(int x, int y) override;
39+
virtual void mouseDown(int button) override;
40+
virtual void mouseUp(int button) override;
41+
virtual void mouseClick(int button) override;
42+
virtual void mouseScrollX(int length) override;
43+
virtual void mouseScrollY(int length) override;
44+
45+
virtual void keyDown(int key) override;
46+
virtual void keyUp(int key) override;
47+
};
48+
49+
#endif // XINPUTSIMULAROTIMPLWIN_H
50+
51+
#endif //win

0 commit comments

Comments
 (0)