0

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

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by thecoolman5
0

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
0

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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.