Find the answer to your Linux question:
Results 1 to 2 of 2
Hi guys, I am new x11 programming. I want to know the APIs for moving the cursor on the screen. Cursor in the sense mouse pointer. Is there is any ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2006
    Posts
    24

    using X11


    Hi guys,
    I am new x11 programming. I want to know the APIs for moving the cursor on the screen. Cursor in the sense mouse pointer. Is there is any way to move the mouse pointer on the screen from the application.

  2. #2
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    This should probably go in the Programming Forum, but...

    Try XWarpPointer found in Xlib.h:
    Code:
    #include <X11/Xlib.h>
    #include <stdio.h>
    
    int main(void) {
      Display *dsp;
      Window root;
    
      dsp = XOpenDisplay(NULL);
      if(! dsp) {
         fprintf(stderr, "Unable to connect to X Display\n");
         exit(1);
      }
    
      root = RootWindow(dsp, DefaultScreen(dsp));
      /* This line moves the pointer to (100, 100) on the screen */
      XWarpPointer(dsp, None, root, 0, 0, 0, 0, 100, 100);
      XFlush(dsp);
      return 0;
    }
    And to compile, you need the -lX11 option.
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •