Hi. I've made a code. The code is not 100% working, so i ned help with that.
The tiny litle program is gonna work so it move the mouse, and then click with it. Both right and left click. And i don't know how to do that?

#include <iostream>
#include <X11/Xlib.h>

using namespace std;

void click_with_mouse(){

    int delta_x = 450, delta_y = 780;
    Display *display = XOpenDisplay(0);
    Window root = DefaultRootWindow(display);
    XWarpPointer(display, None, root, 0, 0, 0, 0, delta_x, delta_y);
    XCloseDisplay(display);
}


int main()
{

    cout << "Hi, now the mouse is on X = 450 and Y = 780 :)";
    click_with_mouse();
    return 0;

}

I will be very happy for help :)
//Heavy

Recommended Answers

All 4 Replies

This should work.

mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // Left click
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); // Right click

And to move the mouse,

SetCursorPos(x,y);

What? Here's the full sorce code.

#include<iostream>
#include<windows.h>
using namespace std;
int main (char argc)
{
           cout << "Hi, now the mouse is on X = 450 and Y = 780 :)";
           SetCursorPos(450, 780);
            
           mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // Left click
           mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); // Right click
           return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.