简体   繁体   English

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

[英]How to move the mouse cursor from user code?

My data comes from an arduino (which gets it from a sensor).我的数据来自 arduino(从传感器获取)。
I'd like to have the data processed by an user program (after reading it from /dev/ttyUSB0 ).我想让用户程序处理数据(从 /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)?执行此操作的推荐方法是什么(在 Linux 环境中)?
Perhaps a library on top of X...or some tool/script I can directly pipe the data into?也许是一个基于 X 的库……或者一些我可以直接将数据通过管道传输的工具/脚本?

Taken from dzone :取自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 xte 是一个命令行工具: 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如果您可以使用 python,xaut 可能更符合您的喜好: http ://xautomation.sourceforge.net/index.html

Or with node-x11 :或者使用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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM