如何在Linux上设置C小鼠光标位置? [英] How to set mouse cursor position in C on linux?

查看:174
本文介绍了如何在Linux上设置C小鼠光标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置使用Linux下的C程序一个X窗口中的鼠标光标位置?
谢谢 :)
(如setcursorpos()在WIN)

编辑:
我已经试过这code,但不工作:

 的#include<&curses.h里GT;主要(){
 移动(100,100);
 刷新();
}


解决方案

12.4 - 移动指针


  

虽然指针的移动
  通常的留给控制
  最终用户,有时是
  必须将指针移动到一个新
  程序控制下的位置。


  
  

要指针移动到任意
  在一个窗口点,使用 XWarpPointer()



示例:

 显示* DPY;
窗口root_window;DPY = XOpenDisplay(0);
root_window = XRootWindow(DPY,0);
XSelectInput(DPY,root_window,KeyReleaseMask);
XWarpPointer(DPY,无,root_window,0,0,0,0,100,100);
XFlush(DPY); //刷新输出缓冲区,因此更新光标位置。由于水委。

how can I set the mouse cursor position in an X window using a C program under Linux? thanks :) (like setcursorpos() in WIN)

EDIT: I've tried this code, but doesn't work:

#include <curses.h>

main(){
 move(100, 100);
 refresh();
}

解决方案

12.4 - Moving the Pointer

Although movement of the pointer normally should be left to the control of the end user, sometimes it is necessary to move the pointer to a new position under program control.

To move the pointer to an arbitrary point in a window, use XWarpPointer().


Example:

Display *dpy;
Window root_window;

dpy = XOpenDisplay(0);
root_window = XRootWindow(dpy, 0);
XSelectInput(dpy, root_window, KeyReleaseMask);
XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, 100, 100);
XFlush(dpy); // Flushes the output buffer, therefore updates the cursor's position. Thanks to Achernar.

这篇关于如何在Linux上设置C小鼠光标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆