在 X11 上移动鼠标光标无法按预期工作
我试图在按下左按钮(Button1)时移动鼠标指针。 但这不起作用。例如,如果我启动 GIMP,我会看到一个点(光标向下),然后光标移动但不绘图。我期待看到一条画线(按住左键移动)。
Display * display = XOpenDisplay(0);
XEvent event;
memset (&event, 0, sizeof (event));
event.xbutton.button = Button1;
event.xbutton.same_screen = True;
event.xbutton.subwindow = DefaultRootWindow (display);
while (event.xbutton.subwindow)
{
event.xbutton.window = event.xbutton.subwindow;
XQueryPointer (display, event.xbutton.window,
&event.xbutton.root, &event.xbutton.subwindow,
&event.xbutton.x_root, &event.xbutton.y_root,
&event.xbutton.x, &event.xbutton.y,
&event.xbutton.state);
}
// Press
event.type = ButtonPress;
if (XSendEvent (display, PointerWindow, True, 0xFFF, &event) == 0)
fprintf (stderr, "Error to send the event!\n");
XFlush (display);
// Move
XWarpPointer(display, None, 0, 0, 0, 0, 0, 50, 50);
XFlush (display);
// Release
event.type = ButtonRelease;
event.xbutton.state = 0x100;
if (XSendEvent (display, PointerWindow, True, 0xFFF, &event) == 0)
fprintf (stderr, "Error to send the event!\n");
XFlush (display);
我做错了什么?
谢谢!
尼古拉斯.
I'm trying to move the mouse pointer while the left button is down (Button1).
But it doesn't work. For example, if I launch GIMP, I see a dot (cursor down), then the cursor moves but without drawing. I was expecting to see a drawn line (move while holding left button down).
Display * display = XOpenDisplay(0);
XEvent event;
memset (&event, 0, sizeof (event));
event.xbutton.button = Button1;
event.xbutton.same_screen = True;
event.xbutton.subwindow = DefaultRootWindow (display);
while (event.xbutton.subwindow)
{
event.xbutton.window = event.xbutton.subwindow;
XQueryPointer (display, event.xbutton.window,
&event.xbutton.root, &event.xbutton.subwindow,
&event.xbutton.x_root, &event.xbutton.y_root,
&event.xbutton.x, &event.xbutton.y,
&event.xbutton.state);
}
// Press
event.type = ButtonPress;
if (XSendEvent (display, PointerWindow, True, 0xFFF, &event) == 0)
fprintf (stderr, "Error to send the event!\n");
XFlush (display);
// Move
XWarpPointer(display, None, 0, 0, 0, 0, 0, 50, 50);
XFlush (display);
// Release
event.type = ButtonRelease;
event.xbutton.state = 0x100;
if (XSendEvent (display, PointerWindow, True, 0xFFF, &event) == 0)
fprintf (stderr, "Error to send the event!\n");
XFlush (display);
What am I doing wrong?
Thanks!
Nicolas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 XTest 扩展库来伪造用户输入事件。
Use the XTest extension library to fake user input events.