[ale] placing mouse at absolute coordinate on screen

Mike Fletcher fletch at phydeaux.org
Wed Aug 5 08:54:48 EDT 1998


> is there an X utility to place mouse cursor at an *arbitrary* coordinate on
> screen ?  (not to a coordinate *relative* to a window  -- unless it were
> the root window of course)
> 
> man -k only mentions a related function XWarpPointer().
> 
> --  i want to be able to invoke such command and place the mouse at center
> 	of screen. (for times when the critter is hiding)
> 
> if anyone has a home-brewed utility to do this, or a way to do it from
> fvwm2, plz let me know.

	Changing this to allow arbitrary positioning is, of course, 
left as an exercise for the reader.

/*
 * gcc -o wc wc.c -L/usr/X11R6/lib -lX11 -lm
 */
#include <stdio.h>
#include <unistd.h>
#include <X11/Xlib.h>

int main( int argc, char **argv )
{ 
  Display *dpy;
  Window  win;
  int     x, y;

  if( !(dpy = XOpenDisplay( NULL )) ) {
    fprintf( stderr, "Can't connect to display\n" );
    exit( 1 );
  }

  x = WidthOfScreen(ScreenOfDisplay(dpy, DefaultScreen(dpy))) / 2;
  y = HeightOfScreen(ScreenOfDisplay(dpy, DefaultScreen(dpy))) / 2;

  if( !(win = DefaultRootWindow( dpy )) ) {
    fprintf( stderr, "Can't get root window\n" );
    exit( 1 );
  }

  XWarpPointer( dpy, None, win, 0, 0, 0, 0, x, y );

  XCloseDisplay( dpy );
  exit( 0 );
}

-- 
Fletch                |                                            __`'/|
fletch at phydeaux.org   |       "I drank what?" -- Socrates          \ o.O'
678 443-6239(w)       |                                            =(___)=
                      |                                               U






More information about the Ale mailing list