Skip to content

Commit df5b985

Browse files
committed
first non working version
1 parent b1896f0 commit df5b985

10 files changed

+248
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
#ide specific files
1616
*.pro
1717
*.user
18-
*.directory
18+
*.directory
19+
build-*

XInputSimulator/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#include <iostream>
2+
#include "xinputsimulator.h"
23

34
using namespace std;
45

56
int main()
67
{
78
cout << "Hello World!" << endl;
9+
10+
XInputSimulator &sim = XInputSimulator::getInstance();
11+
sim.mouseMoveTo(1,2);
12+
sim.mouseClick(1);
13+
814
return 0;
915
}
1016

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "notimplementedexception.h"
2+
3+
NotImplementedException::NotImplementedException()
4+
:
5+
std::runtime_error("The author was to lazy to implement this function yet...")
6+
{
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef NOTIMPLEMENTEDEXCEPTION_H
2+
#define NOTIMPLEMENTEDEXCEPTION_H
3+
4+
#include <stdexcept>
5+
6+
class NotImplementedException : public std::runtime_error
7+
{
8+
public:
9+
NotImplementedException();
10+
};
11+
12+
#endif // NOTIMPLEMENTEDEXCEPTION_H

XInputSimulator/xinputsimulator.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "xinputsimulator.h"
2+
3+
void XInputSimulator::mouseMoveTo(int x, int y)
4+
{
5+
implementation->mouseMoveTo(x, y);
6+
}
7+
8+
void XInputSimulator::mouseMoveRelative(int x, int y)
9+
{
10+
implementation->mouseMoveRelative(x, y);
11+
}
12+
13+
void XInputSimulator::mouseDown(int button)
14+
{
15+
implementation->mouseDown(button);
16+
}
17+
18+
void XInputSimulator::mouseUp(int button)
19+
{
20+
implementation->mouseUp(button);
21+
}
22+
23+
void XInputSimulator::mouseClick(int button)
24+
{
25+
implementation->mouseClick(button);
26+
}
27+
28+
void XInputSimulator::mouseScrollX(int length)
29+
{
30+
implementation->mouseScrollX(length);
31+
}
32+
33+
void XInputSimulator::mouseScrollY(int length)
34+
{
35+
implementation->mouseScrollY(length);
36+
}
37+
38+
void XInputSimulator::keyDown(int key)
39+
{
40+
implementation->keyDown(key);
41+
}
42+
43+
void XInputSimulator::keyUp(int key)
44+
{
45+
implementation->keyUp(key);
46+
}
47+

XInputSimulator/xinputsimulator.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#ifndef XINPUTSIMULATOR_H
2+
#define XINPUTSIMULATOR_H
3+
4+
#include <memory>
5+
#include <mutex>
6+
#include <iostream>
7+
#include "xinputsimulatorimpl.h"
8+
#include "notimplementedexception.h"
9+
10+
#ifdef __linux__
11+
#include "xinputsimulatorimpllinux.h"
12+
#elif __APPLE__
13+
// apple implementation
14+
#elif _WIN32
15+
// win implementation
16+
#endif
17+
18+
class XInputSimulator
19+
{
20+
private:
21+
//XInputSimulator XInputSimulator instance;
22+
//std::unique_ptr<XInputSimulatorImpl> implementation;
23+
XInputSimulatorImpl *implementation;
24+
25+
XInputSimulator(){}
26+
27+
public:
28+
XInputSimulator(XInputSimulator&) = delete;
29+
void operator=(XInputSimulator&) = delete;
30+
31+
~XInputSimulator() {
32+
std::cout << "Singleton::~Singleton" << std::endl;
33+
delete implementation;
34+
}
35+
//TODO add impl choose
36+
static XInputSimulator & getInstance()
37+
{
38+
static XInputSimulator instance;
39+
40+
std::cout << "ThreadSafeSingleton::create_singleton_() "<< std::endl;
41+
42+
#ifdef __linux__
43+
// get linux impl
44+
//instance.implementation = std::move(std::unique_ptr<XInputSimulatorImpl>(new XInputSimulatorImplLinux));
45+
instance.implementation = new XInputSimulatorImplLinux;
46+
#elif __APPLE__
47+
// apple implementation
48+
throw NotImplementedException();
49+
#elif _WIN32
50+
// win implementation
51+
throw NotImplementedException();
52+
#endif
53+
return instance;
54+
}
55+
56+
void mouseMoveTo(int x, int y);//{ implementation->mouseMoveTo(x, y); }
57+
void mouseMoveRelative(int x, int y);
58+
void mouseDown(int button);
59+
void mouseUp(int button);
60+
void mouseClick(int button);
61+
void mouseScrollX(int length);
62+
void mouseScrollY(int length);
63+
64+
void keyDown(int key);
65+
void keyUp(int key);
66+
};
67+
68+
69+
#endif // XINPUTSIMULATOR_H
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "xinputsimulatorimpl.h"
2+
3+
XInputSimulatorImpl::XInputSimulatorImpl()
4+
{
5+
}

XInputSimulator/xinputsimulatorimpl.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef XINPUTSIMULATORIMPL_H
2+
#define XINPUTSIMULATORIMPL_H
3+
4+
class XInputSimulatorImpl
5+
{
6+
public:
7+
XInputSimulatorImpl();
8+
virtual ~XInputSimulatorImpl(){}
9+
10+
virtual void mouseMoveTo(int x, int y) = 0;
11+
virtual void mouseMoveRelative(int x, int y) = 0;
12+
virtual void mouseDown(int button) = 0;
13+
virtual void mouseUp(int button) = 0;
14+
virtual void mouseClick(int button) = 0;
15+
virtual void mouseScrollX(int length) = 0;
16+
virtual void mouseScrollY(int length) = 0;
17+
18+
virtual void keyDown(int key) = 0;
19+
virtual void keyUp(int key) = 0;
20+
21+
};
22+
23+
#endif // XINPUTSIMULATORIMPL_H
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "xinputsimulatorimpllinux.h"
2+
#include "notimplementedexception.h"
3+
#include <iostream>
4+
5+
XInputSimulatorImplLinux::XInputSimulatorImplLinux()
6+
{
7+
}
8+
9+
void XInputSimulatorImplLinux::mouseMoveTo(int x, int y)
10+
{
11+
std::cout << "move the mouse!\n";
12+
}
13+
14+
void XInputSimulatorImplLinux::mouseMoveRelative(int x, int y)
15+
{
16+
throw NotImplementedException();
17+
}
18+
19+
void XInputSimulatorImplLinux::mouseDown(int button)
20+
{
21+
throw NotImplementedException();
22+
}
23+
24+
void XInputSimulatorImplLinux::mouseUp(int button)
25+
{
26+
throw NotImplementedException();
27+
}
28+
29+
void XInputSimulatorImplLinux::mouseClick(int button)
30+
{
31+
throw NotImplementedException();
32+
}
33+
34+
void XInputSimulatorImplLinux::mouseScrollX(int length)
35+
{
36+
throw NotImplementedException();
37+
}
38+
39+
void XInputSimulatorImplLinux::mouseScrollY(int length)
40+
{
41+
throw NotImplementedException();
42+
}
43+
44+
void XInputSimulatorImplLinux::keyDown(int key)
45+
{
46+
throw NotImplementedException();
47+
}
48+
49+
void XInputSimulatorImplLinux::keyUp(int key)
50+
{
51+
throw NotImplementedException();
52+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef XINPUTSIMULATORIMPLLINUX_H
2+
#define XINPUTSIMULATORIMPLLINUX_H
3+
4+
#include "xinputsimulatorimpl.h"
5+
6+
class XInputSimulatorImplLinux : public XInputSimulatorImpl
7+
{
8+
public:
9+
XInputSimulatorImplLinux();
10+
~XInputSimulatorImplLinux(){}
11+
12+
virtual void mouseMoveTo(int x, int y) override;
13+
virtual void mouseMoveRelative(int x, int y) override;
14+
virtual void mouseDown(int button) override;
15+
virtual void mouseUp(int button) override;
16+
virtual void mouseClick(int button) override;
17+
virtual void mouseScrollX(int length) override;
18+
virtual void mouseScrollY(int length) override;
19+
20+
virtual void keyDown(int key) override;
21+
virtual void keyUp(int key) override;
22+
23+
};
24+
25+
#endif // XINPUTSIMULATORIMPLLINUX_H

0 commit comments

Comments
 (0)