如何从用户代码中移动鼠标光标

How to move the mouse cursor from user code?

本文关键字:移动 鼠标 光标 代码 用户      更新时间:2023-10-16

我的数据来自arduino(它从传感器获得数据)
我想让用户程序处理数据(从/dev/ttyUSB0中读取数据后)
之后,我需要使用程序的输出来控制鼠标光标
(我现在真的不想写内核驱动程序。)

建议的方法是什么(在Linux环境中)
也许是X之上的库…或者是我可以直接将数据导入的某种工具/脚本?

取自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);
}

我知道有几个选项:

  1. xte是一个命令行工具:http://linux.die.net/man/1/xte
  2. 如果你能使用python,xaut可能更符合你的喜好:http://xautomation.sourceforge.net/index.html

或者使用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);
});