added impl of linux mousemoveto and mousemoverelative
This commit is contained in:
parent
df79f226b4
commit
73d19c6317
|
@ -18,6 +18,9 @@
|
|||
#include <iostream>
|
||||
#include "xinputsimulator.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
|
@ -25,8 +28,9 @@ int main()
|
|||
cout << "Hello World!" << endl;
|
||||
|
||||
XInputSimulator &sim = XInputSimulator::getInstance();
|
||||
sim.mouseMoveTo(1,2);
|
||||
sim.mouseClick(1);
|
||||
sim.mouseMoveTo(100,200);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
sim.mouseMoveRelative(400, -100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,21 +1,3 @@
|
|||
#include "xinputsimulatorimpllinux.h"
|
||||
#include "notimplementedexception.h"
|
||||
#include <iostream>
|
||||
|
||||
XInputSimulatorImplLinux::XInputSimulatorImplLinux()
|
||||
{
|
||||
}
|
||||
|
||||
void XInputSimulatorImplLinux::mouseMoveTo(int x, int y)
|
||||
{
|
||||
std::cout << "move the mouse!\n";
|
||||
}
|
||||
|
||||
void XInputSimulatorImplLinux::mouseMoveRelative(int x, int y)
|
||||
{
|
||||
throw NotImplementedException();
|
||||
}
|
||||
|
||||
// Copyright 2013 Dustin Bensing
|
||||
|
||||
// This file is part of XInputSimulator.
|
||||
|
@ -33,6 +15,44 @@ void XInputSimulatorImplLinux::mouseMoveRelative(int x, int y)
|
|||
// You should have received a copy of the GNU Lesser Public License
|
||||
// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "xinputsimulatorimpllinux.h"
|
||||
#include "notimplementedexception.h"
|
||||
#include <iostream>
|
||||
|
||||
XInputSimulatorImplLinux::XInputSimulatorImplLinux()
|
||||
{
|
||||
if((display = XOpenDisplay(NULL)) == NULL) {
|
||||
std::cout << "can not access display server!" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
root = DefaultRootWindow(display);
|
||||
}
|
||||
|
||||
void XInputSimulatorImplLinux::mouseMoveTo(int x, int y)
|
||||
{
|
||||
std::cout << "move the mouse!\n";
|
||||
|
||||
if(!display){
|
||||
return;
|
||||
}
|
||||
|
||||
XWarpPointer(display, None, root, 0, 0, 0, 0, x, y);
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
void XInputSimulatorImplLinux::mouseMoveRelative(int x, int y)
|
||||
{
|
||||
//throw NotImplementedException();
|
||||
|
||||
if(!display){
|
||||
return;
|
||||
}
|
||||
|
||||
XWarpPointer(display, None, None, 0, 0, 0, 0, x, y);
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
void XInputSimulatorImplLinux::mouseDown(int button)
|
||||
{
|
||||
throw NotImplementedException();
|
||||
|
|
|
@ -18,13 +18,20 @@
|
|||
#ifndef XINPUTSIMULATORIMPLLINUX_H
|
||||
#define XINPUTSIMULATORIMPLLINUX_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include "xinputsimulatorimpl.h"
|
||||
|
||||
class XInputSimulatorImplLinux : public XInputSimulatorImpl
|
||||
{
|
||||
private:
|
||||
Display *display;
|
||||
Window root;
|
||||
|
||||
public:
|
||||
XInputSimulatorImplLinux();
|
||||
~XInputSimulatorImplLinux(){}
|
||||
~XInputSimulatorImplLinux(){ delete display; }
|
||||
|
||||
virtual void mouseMoveTo(int x, int y) override;
|
||||
virtual void mouseMoveRelative(int x, int y) override;
|
||||
|
|
Loading…
Reference in New Issue