How to move the mouse cursor from user code?

2019-04-10 20:19发布

My data comes from an arduino (which gets it from a sensor).
I'd like to have the data processed by an user program (after reading it from /dev/ttyUSB0 ).
After that I need to control the mouse cursor using the output of the program.
(I'd really like to avoid writing a kernel driver at this moment.)

What is the recommended way to do this(on a Linux environment)?
Perhaps a library on top of X...or some tool/script I can directly pipe the data into?

3条回答
2楼-- · 2019-04-10 20:34

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
查看更多
在下西门庆
3楼-- · 2019-04-10 20:34

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);
});
查看更多
叼着烟拽天下
4楼-- · 2019-04-10 20:57

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);
}
查看更多
登录 后发表回答