I need to capture screen (as print screen) in the way so I can access pixel color data, to do some image recognition, after that I will need to generate mouse events on the
I couldn't get the clicking working with the method @axiom used, only movement of the pointer. I used this instead: (Ubuntu 18.04).
Compiles with: g++ mouse_click.cpp -lX11 -lXtst -lstdc++
#include
#include
#include
#include
#include
#include
#include
#include
void mouseClick(int button)
{
Display *display = XOpenDisplay(NULL);
// click left button
XTestFakeButtonEvent(display, Button1, true, 0);
XFlush(display);
usleep(10000);
// release left mouse
XTestFakeButtonEvent(display, Button1, false, 0);
XFlush(display);
XCloseDisplay(display);
}
int main(int argc,char * argv[]) {
int x , y;
x=atoi(argv[1]);
y=atoi(argv[2]);
Display *display = XOpenDisplay(0);
Window root = DefaultRootWindow(display);
XTestFakeMotionEvent(display, root, x, y, 0);
XFlush(display);
mouseClick(Button1);
XFlush(display);
XCloseDisplay(display);
return 0;
}