gpt4 book ai didi

c - 如何在 Linux 上的 C 中设置鼠标光标位置?

转载 作者:IT王子 更新时间:2023-10-29 00:17:13 26 4
gpt4 key购买 nike

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

编辑:我试过这段代码,但不起作用:

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


示例:

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.

关于c - 如何在 Linux 上的 C 中设置鼠标光标位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2433447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com