How to move the mouse cursor from user code?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 13:57:13

Taken from dzone:

#include <stdio.h>
#include <stdlib.h>

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

void mouseMove(int x, int y)
{
    Display *displayMain = XOpenDisplay(NULL);

    if(displayMain == NULL)
    {
        fprintf(stderr, "Errore nell'apertura del Display !!!\n");
        exit(EXIT_FAILURE);
    }

    XWarpPointer(displayMain, None, None, 0, 0, 0, 0, x, y);

    XCloseDisplay(displayMain);
}

There are a few options I know of:

  1. xte is a command line tool: http://linux.die.net/man/1/xte
  2. if you can use python, xaut might be more to your liking: http://xautomation.sourceforge.net/index.html

Or with node-x11:

var x = 100; 
var y = 200;
require('x11').createClient(function(err, display) {
    display.client.WarpPointer(0, display.screen[0].root, 0, 0, 0, 0, x, y);
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!