本文介绍了如何从用户代码中移动鼠标光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据来自arduino(从传感器获取).
我想由用户程序处理数据(从/dev/ttyUSB0读取数据之后).
之后,我需要使用程序的输出来控制鼠标光标.
(我真的很想避免在此刻编写内核驱动程序.)

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.)

(在Linux环境上)推荐的这样做方式是什么?
也许是X之上的库...或我可以直接将数据传递到其中的某些工具/脚本?

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?

推荐答案

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

这篇关于如何从用户代码中移动鼠标光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:38