• How do I get coordinates or mouse clicks C/C++, Linux?

    From fsn761304@gmail.com@21:1/5 to All on Sun Dec 13 13:06:36 2015
    I have a code which does it, but when it works its difficult to interact with a desktop - I need to click several times on something to access it. (prefer license which will not demand to disclose source code) Here is the link to the code which I use:

    #include <stdio.h>
    #include <stdlib.h>
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>

    int main (){
    int x=-1,y=-1;
    XEvent event;
    int button;
    Display *display = XOpenDisplay(NULL);
    if (display == NULL) {
    fprintf(stderr, "Cannot connect to X server!\n");
    exit (EXIT_FAILURE);
    }
    Window root= XDefaultRootWindow(display);
    XGrabPointer(display, root, False, ButtonPressMask, GrabModeAsync,
    GrabModeAsync, None, None, CurrentTime);

    XSelectInput(display, root, ButtonPressMask) ;
    while(1){
    XNextEvent(display,&event);
    switch(event.type){
    case ButtonPress:
    switch(event.xbutton.button){
    case Button1:
    x=event.xbutton.x;
    y=event.xbutton.y;
    button=Button1;
    break;

    case Button3:
    x=event.xbutton.x;
    y=event.xbutton.y;
    button=Button3;
    break;
    default:
    break;

    }
    break;
    default:
    break;
    }
    if(x>=0 && y>=0)break;
    }
    if(button==Button1)printf("leftclick at %d %d \n",x,y);
    else printf("rightclick at %d %d \n",x,y);
    XCloseDisplay(display);
    return 0;
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From fsn761304@gmail.com@21:1/5 to Tauno Voipio on Tue Dec 15 02:31:10 2015
    On Monday, December 14, 2015 at 11:24:56 PM UTC+4, Tauno Voipio wrote:
    On 13.12.15 23:06, fsn761304@gmail.com wrote:
    I have a code which does it, but when it works its difficult to interact with a desktop - I need to click several times on something to access it. (prefer license which will not demand to disclose source code) Here is the link to the code which I use:

    #include <stdio.h>
    #include <stdlib.h>
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>

    int main (){
    int x=-1,y=-1;
    XEvent event;
    int button;
    Display *display = XOpenDisplay(NULL);
    if (display == NULL) {
    fprintf(stderr, "Cannot connect to X server!\n");
    exit (EXIT_FAILURE);
    }
    Window root= XDefaultRootWindow(display);
    XGrabPointer(display, root, False, ButtonPressMask, GrabModeAsync,
    GrabModeAsync, None, None, CurrentTime);

    XSelectInput(display, root, ButtonPressMask) ;
    while(1){
    XNextEvent(display,&event);
    switch(event.type){
    case ButtonPress:
    switch(event.xbutton.button){
    case Button1:
    x=event.xbutton.x;
    y=event.xbutton.y;
    button=Button1;
    break;

    case Button3:
    x=event.xbutton.x;
    y=event.xbutton.y;
    button=Button3;
    break;
    default:
    break;

    }
    break;
    default:
    break;
    }
    if(x>=0 && y>=0)break;
    }
    if(button==Button1)printf("leftclick at %d %d \n",x,y);
    else printf("rightclick at %d %d \n",x,y);
    XCloseDisplay(display);
    return 0;
    }


    What are you attempting to achieve?

    A clandestine mouse logger?

    --

    -TV

    I want screenshot of specific part of screen, then OCR recognition.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jasen Betts@21:1/5 to fsn761304@gmail.com on Mon Dec 14 08:33:45 2015
    On 2015-12-13, fsn761304@gmail.com <fsn761304@gmail.com> wrote:
    I have a code which does it, but when it works its difficult to
    interact with a desktop - I need to click several times on something
    to access it. (prefer license which will not demand to disclose source
    code) Here is the link to the code which I use:

    QT is available for closed source IIRC, might have to pay some.
    it's not pure C++ thoough

    --
    \_(ツ)_

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tauno Voipio@21:1/5 to fsn761304@gmail.com on Mon Dec 14 21:24:53 2015
    On 13.12.15 23:06, fsn761304@gmail.com wrote:
    I have a code which does it, but when it works its difficult to interact with a desktop - I need to click several times on something to access it. (prefer license which will not demand to disclose source code) Here is the link to the code which I use:

    #include <stdio.h>
    #include <stdlib.h>
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>

    int main (){
    int x=-1,y=-1;
    XEvent event;
    int button;
    Display *display = XOpenDisplay(NULL);
    if (display == NULL) {
    fprintf(stderr, "Cannot connect to X server!\n");
    exit (EXIT_FAILURE);
    }
    Window root= XDefaultRootWindow(display);
    XGrabPointer(display, root, False, ButtonPressMask, GrabModeAsync,
    GrabModeAsync, None, None, CurrentTime);

    XSelectInput(display, root, ButtonPressMask) ;
    while(1){
    XNextEvent(display,&event);
    switch(event.type){
    case ButtonPress:
    switch(event.xbutton.button){
    case Button1:
    x=event.xbutton.x;
    y=event.xbutton.y;
    button=Button1;
    break;

    case Button3:
    x=event.xbutton.x;
    y=event.xbutton.y;
    button=Button3;
    break;
    default:
    break;

    }
    break;
    default:
    break;
    }
    if(x>=0 && y>=0)break;
    }
    if(button==Button1)printf("leftclick at %d %d \n",x,y);
    else printf("rightclick at %d %d \n",x,y);
    XCloseDisplay(display);
    return 0;
    }


    What are you attempting to achieve?

    A clandestine mouse logger?

    --

    -TV

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)