mac port same level as linux
This commit is contained in:
parent
3fb1b37b8e
commit
a1b583595a
|
@ -16,4 +16,5 @@
|
|||
*.pro
|
||||
*.user
|
||||
*.directory
|
||||
build-*
|
||||
build-*
|
||||
*build-*
|
|
@ -18,8 +18,10 @@
|
|||
#include <iostream>
|
||||
#include "xinputsimulator.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
//#include <chrono>
|
||||
//#include <thread>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -30,6 +32,8 @@ int main()
|
|||
cout << "Hello World!" << endl;
|
||||
|
||||
XInputSimulator &sim = XInputSimulator::getInstance();
|
||||
waitABit();
|
||||
waitABit();
|
||||
sim.mouseMoveTo(500,400);
|
||||
waitABit();
|
||||
sim.mouseMoveRelative(400, -100);
|
||||
|
@ -50,10 +54,13 @@ int main()
|
|||
waitABit();
|
||||
sim.mouseScrollX(-10);
|
||||
|
||||
|
||||
waitABit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void waitABit()
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
sleep(2);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#define XINPUTSIMULATOR_H
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
//#include <mutex>
|
||||
#include <iostream>
|
||||
#include "xinputsimulatorimpl.h"
|
||||
#include "notimplementedexception.h"
|
||||
|
@ -27,7 +27,7 @@
|
|||
#ifdef __linux__
|
||||
#include "xinputsimulatorimpllinux.h"
|
||||
#elif __APPLE__
|
||||
// apple implementation
|
||||
#include "xinputsimulatorimplmacos.h"
|
||||
#elif _WIN32
|
||||
// win implementation
|
||||
#endif
|
||||
|
@ -61,8 +61,7 @@ public:
|
|||
//instance.implementation = std::move(std::unique_ptr<XInputSimulatorImpl>(new XInputSimulatorImplLinux));
|
||||
instance.implementation = new XInputSimulatorImplLinux;
|
||||
#elif __APPLE__
|
||||
// apple implementation
|
||||
throw NotImplementedException();
|
||||
instance.implementation = new XInputSimulatorImplMacOs;
|
||||
#elif _WIN32
|
||||
// win implementation
|
||||
throw NotImplementedException();
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
// You should have received a copy of the GNU Lesser Public License
|
||||
// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
#include "xinputsimulatorimpllinux.h"
|
||||
#include "notimplementedexception.h"
|
||||
#include <iostream>
|
||||
|
@ -24,8 +26,8 @@
|
|||
#include <cstring>
|
||||
|
||||
//sleep
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
//#include <chrono>
|
||||
//#include <thread>
|
||||
|
||||
XInputSimulatorImplLinux::XInputSimulatorImplLinux()
|
||||
{
|
||||
|
@ -109,7 +111,7 @@ void XInputSimulatorImplLinux::mouseClick(int button)
|
|||
{
|
||||
//throw NotImplementedException();
|
||||
this->mouseDown(button);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
this->mouseUp(button);
|
||||
}
|
||||
//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
|
||||
|
@ -166,3 +168,6 @@ void XInputSimulatorImplLinux::keyUp(int key)
|
|||
{
|
||||
throw NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
#endif // linux
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
// You should have received a copy of the GNU Lesser Public License
|
||||
// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
#ifndef XINPUTSIMULATORIMPLLINUX_H
|
||||
#define XINPUTSIMULATORIMPLLINUX_H
|
||||
|
||||
|
@ -50,3 +52,5 @@ public:
|
|||
};
|
||||
|
||||
#endif // XINPUTSIMULATORIMPLLINUX_H
|
||||
|
||||
#endif // linux
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
#ifdef __APPLE__
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//quartz CG... stuff
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
//sleep
|
||||
#include <unistd.h>
|
||||
|
||||
#include "xinputsimulatorimplmacos.h"
|
||||
#include "notimplementedexception.h"
|
||||
|
||||
|
||||
|
||||
XInputSimulatorImplMacOs::XInputSimulatorImplMacOs()
|
||||
{
|
||||
//this->initCurrentMousePosition();
|
||||
|
||||
this->currentX = 500;
|
||||
this->currentY = 500;
|
||||
}
|
||||
|
||||
//void XInputSimulatorImplMacOs::initMouseEvent(int button)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
void XInputSimulatorImplMacOs::initCurrentMousePosition()
|
||||
{
|
||||
throw NotImplementedException();
|
||||
}
|
||||
|
||||
void XInputSimulatorImplMacOs::mouseMoveTo(int x, int y)
|
||||
{
|
||||
std::cout << "moveTo mac\n";
|
||||
|
||||
CGEventRef mouseEv = CGEventCreateMouseEvent(
|
||||
NULL, kCGEventMouseMoved,
|
||||
CGPointMake(x, y),
|
||||
kCGMouseButtonLeft);
|
||||
|
||||
std::cout << "mv: " << mouseEv << std::endl;
|
||||
|
||||
CGEventPost(kCGHIDEventTap, mouseEv);
|
||||
|
||||
CFRelease(mouseEv);
|
||||
|
||||
this->currentX = x;
|
||||
this->currentY = y;
|
||||
}
|
||||
|
||||
void XInputSimulatorImplMacOs::mouseMoveRelative(int x, int y)
|
||||
{
|
||||
std::cout << "moveRelative mac\n";
|
||||
|
||||
int newX = this->currentX + x;
|
||||
int newY = this->currentY + y;
|
||||
|
||||
std::cout << "newx: " << newX << " newy: " << newY << std::endl;
|
||||
|
||||
CGEventRef mouseEv = CGEventCreateMouseEvent(
|
||||
NULL, kCGEventMouseMoved,
|
||||
CGPointMake(newX, newY),
|
||||
kCGMouseButtonLeft);
|
||||
|
||||
CGEventPost(kCGHIDEventTap, mouseEv);
|
||||
|
||||
CFRelease(mouseEv);
|
||||
|
||||
this->currentX = newX;
|
||||
this->currentY = newY;
|
||||
}
|
||||
|
||||
//TODO use the button from parameter list
|
||||
void XInputSimulatorImplMacOs::mouseDown(int button)
|
||||
{
|
||||
//throw NotImplementedException();
|
||||
|
||||
std::cout << "mouseDown mac\n";
|
||||
|
||||
CGEventRef mouseEv = CGEventCreateMouseEvent(
|
||||
NULL, kCGEventLeftMouseDown,
|
||||
CGPointMake(this->currentX, this->currentY),
|
||||
kCGMouseButtonLeft); // use int buttn from parameter
|
||||
|
||||
CGEventPost(kCGHIDEventTap, mouseEv);
|
||||
|
||||
CFRelease(mouseEv);
|
||||
|
||||
}
|
||||
|
||||
//TODO use the button from parameter list
|
||||
void XInputSimulatorImplMacOs::mouseUp(int button)
|
||||
{
|
||||
//throw NotImplementedException();
|
||||
|
||||
std::cout << "mouseDown mac\n";
|
||||
|
||||
CGEventRef mouseEv = CGEventCreateMouseEvent(
|
||||
NULL, kCGEventLeftMouseUp,
|
||||
CGPointMake(this->currentX, this->currentY),
|
||||
kCGMouseButtonLeft); // use int buttn from parameter
|
||||
|
||||
CGEventPost(kCGHIDEventTap, mouseEv);
|
||||
|
||||
CFRelease(mouseEv);
|
||||
}
|
||||
|
||||
void XInputSimulatorImplMacOs::mouseClick(int button)
|
||||
{
|
||||
//throw NotImplementedException();
|
||||
this->mouseDown(button);
|
||||
this->mouseUp(button);
|
||||
}
|
||||
//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
|
||||
void XInputSimulatorImplMacOs::mouseScrollX(int length)
|
||||
{
|
||||
//throw NotImplementedException();
|
||||
|
||||
std::cout << "scroll x mac " << length << std::endl;
|
||||
|
||||
int scrollDirection = -1; // 1 left -1 right
|
||||
|
||||
if(length < 0){
|
||||
length *= -1;
|
||||
scrollDirection *= -1;
|
||||
}
|
||||
|
||||
//length *= 100;
|
||||
|
||||
for(int cnt = 0; cnt < length; cnt++){
|
||||
|
||||
std::cout << "scroll y mac" << std::endl;
|
||||
|
||||
CGEventRef scrollEv = CGEventCreateScrollWheelEvent (
|
||||
NULL, kCGScrollEventUnitLine, // kCGScrollEventUnitLine //kCGScrollEventUnitPixel
|
||||
2, //CGWheelCount 1 = y 2 = xy 3 = xyz
|
||||
0,
|
||||
scrollDirection); // length of scroll from -10 to 10 higher values lead to undef behaviour
|
||||
|
||||
CGEventPost(kCGHIDEventTap, scrollEv);
|
||||
|
||||
CFRelease(scrollEv);
|
||||
//sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
void XInputSimulatorImplMacOs::mouseScrollY(int length)
|
||||
{
|
||||
//throw NotImplementedException();
|
||||
|
||||
std::cout << "scroll y mac " << length << std::endl;
|
||||
|
||||
int scrollDirection = -1; // 1 down -1 up
|
||||
|
||||
if(length < 0){
|
||||
length *= -1;
|
||||
scrollDirection *= -1;
|
||||
}
|
||||
|
||||
//length *= 100;
|
||||
|
||||
for(int cnt = 0; cnt < length; cnt++){
|
||||
|
||||
std::cout << "scroll y mac" << std::endl;
|
||||
|
||||
CGEventRef scrollEv = CGEventCreateScrollWheelEvent (
|
||||
NULL, kCGScrollEventUnitLine, // kCGScrollEventUnitLine //kCGScrollEventUnitPixel
|
||||
1, //CGWheelCount 1 = y 2 = xy 3 = xyz
|
||||
scrollDirection); // length of scroll from -10 to 10 higher values lead to undef behaviour
|
||||
|
||||
CGEventPost(kCGHIDEventTap, scrollEv);
|
||||
|
||||
CFRelease(scrollEv);
|
||||
//sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
void XInputSimulatorImplMacOs::keyDown(int key)
|
||||
{
|
||||
throw NotImplementedException();
|
||||
}
|
||||
|
||||
void XInputSimulatorImplMacOs::keyUp(int key)
|
||||
{
|
||||
throw NotImplementedException();
|
||||
}
|
||||
|
||||
#endif //apple
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef XINPUTSIMULATORIMPLMACOS_H
|
||||
#define XINPUTSIMULATORIMPLMACOS_H
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include "xinputsimulatorimpl.h"
|
||||
|
||||
class XInputSimulatorImplMacOs : public XInputSimulatorImpl
|
||||
{
|
||||
private:
|
||||
int currentX;
|
||||
int currentY;
|
||||
|
||||
void initCurrentMousePosition();
|
||||
|
||||
public:
|
||||
XInputSimulatorImplMacOs();
|
||||
~XInputSimulatorImplMacOs(){}
|
||||
|
||||
virtual void mouseMoveTo(int x, int y) override;
|
||||
virtual void mouseMoveRelative(int x, int y) override;
|
||||
virtual void mouseDown(int button) override;
|
||||
virtual void mouseUp(int button) override;
|
||||
virtual void mouseClick(int button) override;
|
||||
virtual void mouseScrollX(int length) override;
|
||||
virtual void mouseScrollY(int length) override;
|
||||
|
||||
virtual void keyDown(int key) override;
|
||||
virtual void keyUp(int key) override;
|
||||
};
|
||||
|
||||
#endif //apple
|
||||
|
||||
#endif // XINPUTSIMULATORIMPLMACOS_H
|
Loading…
Reference in New Issue