Using XTestFakeDeviceMotionEvent().

Chris Ball cjb at laptop.org
Sun Nov 30 23:47:11 PST 2008


Hi,

The following program (requires XInput2) warps my pointer to (0,0)
instead of the requested (600,400).  I'd be interested to know whether
this happens for other people, and if there's something obviously wong
with my code.  Thanks!


// gcc -o xtest xtest.c -Wall -I/usr/include/X11 -lX11 -lXtst -lXext -lXi 
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/extensions/XInput.h>
#define FALSE 0

int main() {
  Display *xdisplay;
  XExtensionVersion *version;
  XDeviceInfo *devInfo;
  XDevice *xdevice;
  int count, i, devPointer;
  int axes[] = {600,400};

  xdisplay = XOpenDisplay(0); 
  version = XQueryInputVersion(xdisplay, 2, 0);

  if (!(devInfo = XListInputDevices(xdisplay, &count)) || !count)
    printf("Cannot list devices\n");

  for (i = 0; i < count; i++) {
    if (devInfo[i].use == IsXPointer)
      devPointer = i; 
  }

  xdevice = XOpenDevice(xdisplay, devInfo[devPointer].id);
  XTestFakeDeviceMotionEvent(xdisplay, xdevice, FALSE, 0, axes, 2, 0);
  XFlush(xdisplay);
  return 0;
}

-- 
Chris Ball   <cjb at laptop.org>



More information about the xorg mailing list