fix x11 c bool define for c++ usage ; add screen bounds check on mac osx
This commit is contained in:
parent
ad2f299445
commit
dd6b347f34
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
|
#include <unistd.h> //usleep
|
||||||
|
|
||||||
#include "xinputsimulatorimpllinux.h"
|
#include "xinputsimulatorimpllinux.h"
|
||||||
#include "notimplementedexception.h"
|
#include "notimplementedexception.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -25,6 +27,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
XInputSimulatorImplLinux::XInputSimulatorImplLinux()
|
XInputSimulatorImplLinux::XInputSimulatorImplLinux()
|
||||||
{
|
{
|
||||||
if((display = XOpenDisplay(NULL)) == NULL) {
|
if((display = XOpenDisplay(NULL)) == NULL) {
|
||||||
|
@ -33,6 +37,13 @@ XInputSimulatorImplLinux::XInputSimulatorImplLinux()
|
||||||
}
|
}
|
||||||
|
|
||||||
root = DefaultRootWindow(display);
|
root = DefaultRootWindow(display);
|
||||||
|
|
||||||
|
Screen* pscr = DefaultScreenOfDisplay( display );
|
||||||
|
|
||||||
|
this->displayX = pscr->width;
|
||||||
|
this->displayY = pscr->height;
|
||||||
|
|
||||||
|
//XCloseDisplay( pdsp );
|
||||||
}
|
}
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::initMouseEvent(int button)
|
void XInputSimulatorImplLinux::initMouseEvent(int button)
|
||||||
|
@ -77,27 +88,20 @@ void XInputSimulatorImplLinux::mouseMoveRelative(int x, int y)
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::mouseDown(int button)
|
void XInputSimulatorImplLinux::mouseDown(int button)
|
||||||
{
|
{
|
||||||
this->initMouseEvent(button);
|
XTestFakeButtonEvent(display, button, true, CurrentTime);
|
||||||
|
|
||||||
event.type = ButtonPress;
|
|
||||||
if (XSendEvent(display, PointerWindow, True, ButtonPressMask, &event) == 0)
|
|
||||||
std::cout << "Error to send the event!\n";
|
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::mouseUp(int button)
|
void XInputSimulatorImplLinux::mouseUp(int button)
|
||||||
{
|
{
|
||||||
this->initMouseEvent(button);
|
XTestFakeButtonEvent(display, button, false, CurrentTime);
|
||||||
|
|
||||||
event.type = ButtonRelease;
|
|
||||||
if (XSendEvent(display, PointerWindow, True, ButtonReleaseMask, &event) == 0)
|
|
||||||
std::cout << "Error to send the event!\n";
|
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::mouseClick(int button)
|
void XInputSimulatorImplLinux::mouseClick(int button)
|
||||||
{
|
{
|
||||||
this->mouseDown(button);
|
this->mouseDown(button);
|
||||||
|
usleep(100);
|
||||||
this->mouseUp(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
|
//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
|
||||||
|
@ -141,14 +145,12 @@ void XInputSimulatorImplLinux::mouseScrollY(int length)
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::keyDown(int key)
|
void XInputSimulatorImplLinux::keyDown(int key)
|
||||||
{
|
{
|
||||||
//throw NotImplementedException();
|
|
||||||
XTestFakeKeyEvent(display, key, True, 0);
|
XTestFakeKeyEvent(display, key, True, 0);
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::keyUp(int key)
|
void XInputSimulatorImplLinux::keyUp(int key)
|
||||||
{
|
{
|
||||||
//throw NotImplementedException();
|
|
||||||
XTestFakeKeyEvent(display, key, False, 0);
|
XTestFakeKeyEvent(display, key, False, 0);
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
}
|
}
|
||||||
|
@ -156,7 +158,7 @@ void XInputSimulatorImplLinux::keyUp(int key)
|
||||||
void XInputSimulatorImplLinux::keyClick(int key)
|
void XInputSimulatorImplLinux::keyClick(int key)
|
||||||
{
|
{
|
||||||
std::cout << "key click: " << key << std::endl;
|
std::cout << "key click: " << key << std::endl;
|
||||||
//throw NotImplementedException();
|
|
||||||
this->keyDown(key);
|
this->keyDown(key);
|
||||||
this->keyUp(key);
|
this->keyUp(key);
|
||||||
}
|
}
|
||||||
|
@ -165,12 +167,6 @@ int XInputSimulatorImplLinux::charToKeyCode(char key_char)
|
||||||
{
|
{
|
||||||
std::cout << "cchar: " << (int)key_char << std::endl;
|
std::cout << "cchar: " << (int)key_char << std::endl;
|
||||||
|
|
||||||
//throw NotImplementedException();
|
|
||||||
|
|
||||||
// KeySym sym = XStringToKeysym(&key_char);
|
|
||||||
|
|
||||||
// std::cout << "sym: " << sym << std::endl;
|
|
||||||
|
|
||||||
int keyCode = XKeysymToKeycode(display, key_char);
|
int keyCode = XKeysymToKeycode(display, key_char);
|
||||||
std::cout << "ccode: " << keyCode << std::endl;
|
std::cout << "ccode: " << keyCode << std::endl;
|
||||||
|
|
||||||
|
@ -178,18 +174,8 @@ int XInputSimulatorImplLinux::charToKeyCode(char key_char)
|
||||||
}
|
}
|
||||||
void XInputSimulatorImplLinux::keySequence(const std::string &sequence)
|
void XInputSimulatorImplLinux::keySequence(const std::string &sequence)
|
||||||
{
|
{
|
||||||
//throw NotImplementedException();
|
|
||||||
|
|
||||||
std::cout << "key seq: " << sequence << std::endl;
|
std::cout << "key seq: " << sequence << std::endl;
|
||||||
|
|
||||||
//c++11 training
|
|
||||||
// for(auto it = sequence.begin(); it != sequence.end(); ++it) {
|
|
||||||
// std::cout << "key org: " << (int)(*it) << std::endl;
|
|
||||||
// int keyCode = this->charToKeyCode(*it);
|
|
||||||
// std::cout << "key code: " << keyCode << std::endl;
|
|
||||||
// this->keyClick(keyCode);
|
|
||||||
// }
|
|
||||||
//c++11 better
|
|
||||||
for(const char c : sequence) {
|
for(const char c : sequence) {
|
||||||
std::cout << "cahr: " << c << std::endl;
|
std::cout << "cahr: " << c << std::endl;
|
||||||
int keyCode = this->charToKeyCode(c);
|
int keyCode = this->charToKeyCode(c);
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/extensions/XTest.h>
|
#include <X11/extensions/XTest.h>
|
||||||
|
|
||||||
|
#undef Bool //fix C #define Bool int in C++ Qt moc from x11
|
||||||
|
|
||||||
#include "xinputsimulatorimpl.h"
|
#include "xinputsimulatorimpl.h"
|
||||||
|
|
||||||
class XInputSimulatorImplLinux : public XInputSimulatorImpl
|
class XInputSimulatorImplLinux : public XInputSimulatorImpl
|
||||||
|
@ -34,6 +36,9 @@ private:
|
||||||
Window root;
|
Window root;
|
||||||
XEvent event;
|
XEvent event;
|
||||||
|
|
||||||
|
size_t displayX;
|
||||||
|
size_t displayY;
|
||||||
|
|
||||||
void initMouseEvent(int button);
|
void initMouseEvent(int button);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -29,15 +29,21 @@
|
||||||
#include "xinputsimulatorimplmacos.h"
|
#include "xinputsimulatorimplmacos.h"
|
||||||
#include "notimplementedexception.h"
|
#include "notimplementedexception.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
XInputSimulatorImplMacOs::XInputSimulatorImplMacOs()
|
XInputSimulatorImplMacOs::XInputSimulatorImplMacOs()
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
//this->initCurrentMousePosition();
|
//this->initCurrentMousePosition();
|
||||||
|
std::cout << "constructor " << std::endl;
|
||||||
this->currentX = 500;
|
this->currentX = 500;
|
||||||
this->currentY = 500;
|
this->currentY = 500;
|
||||||
|
|
||||||
|
CGDirectDisplayID displayID = CGMainDisplayID();
|
||||||
|
|
||||||
|
this->displayX = CGDisplayPixelsWide(displayID);
|
||||||
|
this->displayY = CGDisplayPixelsHigh(displayID);
|
||||||
}
|
}
|
||||||
|
|
||||||
//void XInputSimulatorImplMacOs::initMouseEvent(int button)
|
//void XInputSimulatorImplMacOs::initMouseEvent(int button)
|
||||||
|
@ -53,6 +59,8 @@ void XInputSimulatorImplMacOs::initCurrentMousePosition()
|
||||||
void XInputSimulatorImplMacOs::mouseMoveTo(int x, int y)
|
void XInputSimulatorImplMacOs::mouseMoveTo(int x, int y)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//TODO screen check see moveRelative
|
||||||
|
|
||||||
CGEventRef mouseEv = CGEventCreateMouseEvent(
|
CGEventRef mouseEv = CGEventCreateMouseEvent(
|
||||||
NULL, kCGEventMouseMoved,
|
NULL, kCGEventMouseMoved,
|
||||||
CGPointMake(x, y),
|
CGPointMake(x, y),
|
||||||
|
@ -73,6 +81,12 @@ void XInputSimulatorImplMacOs::mouseMoveRelative(int x, int y)
|
||||||
int newX = this->currentX + x;
|
int newX = this->currentX + x;
|
||||||
int newY = this->currentY + y;
|
int newY = this->currentY + y;
|
||||||
|
|
||||||
|
if(newX < 0 || newX > this->displayX || newY < 0 || newY > this->displayY )
|
||||||
|
{
|
||||||
|
std::cout << "mouse moved beyound screensize." << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "newx: " << newX << " newy: " << newY << std::endl;
|
std::cout << "newx: " << newX << " newy: " << newY << std::endl;
|
||||||
|
|
||||||
CGEventRef mouseEv = CGEventCreateMouseEvent(
|
CGEventRef mouseEv = CGEventCreateMouseEvent(
|
||||||
|
|
|
@ -29,6 +29,9 @@ private:
|
||||||
int currentX;
|
int currentX;
|
||||||
int currentY;
|
int currentY;
|
||||||
|
|
||||||
|
size_t displayX;
|
||||||
|
size_t displayY;
|
||||||
|
|
||||||
void initCurrentMousePosition();
|
void initCurrentMousePosition();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue