【问题标题】:How to move the mouse cursor from user code?如何从用户代码中移动鼠标光标?
【发布时间】:2021-07-10 21:24:30
【问题描述】:

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

推荐的方法是什么(在 Linux 环境中)?
也许是 X 之上的库......或者我可以直接将数据导入的一些工具/脚本?

【问题讨论】:

    标签: c++ linux input xorg


    【解决方案1】:

    我知道有几个选项:

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

    【讨论】:

    • 谢谢,如果我需要,会记住这些。目前,XWarpPointer 似乎表现不错。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-24
        • 1970-01-01
        • 2023-03-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多