gpt4 book ai didi

c - 将事件刷新到 X11

转载 作者:行者123 更新时间:2023-11-30 17:13:04 26 4
gpt4 key购买 nike

我正在创建一个 xlib 应用程序,它将 alt 选项卡发送到 X11我希望尽快刷新这些事件以发送下一个按键组合:

XTestFakeKeyEvent(dis, 64, True, 0);
XTestFakeKeyEvent(dis, 23, True, 0);
XTestFakeKeyEvent(dis, 23, False, 0);
XTestFakeKeyEvent(dis, 64, False, 0);
XFlush(dis);
sleep(1);
XTestFakeKeyEvent(dis, 65, True, 0);
XTestFakeKeyEvent(dis, 65, False, 0);
XFlush(dis);

我希望第一组按键在第二组按键之前工作,不幸的是,除非我让应用程序在两次刷新之间休眠 1 秒,否则这种情况不会发生我也尝试过 xsync,但没有骰子

谢谢

最佳答案

阅读manual page ,与XSync比较:

The XFlush function flushes the output buffer. Most client applications need not use this function because the output buffer is automatically flushed as needed by calls to XPending, XNextEvent, and XWindowEvent. Events generated by the server may be enqueued into the library's event queue.

同时

The XSync function flushes the output buffer and then waits until all requests have been received and processed by the X server. Any errors generated must be handled by the error handler. For each protocol error received by Xlib, XSync calls the client application's error handling routine (see section 11.8.2). Any events generated by the server are enqueued into the library's event queue.

您的应用程序需要等待(并且 sleep 是多余的)。使用XSync

关于c - 将事件刷新到 X11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31088029/

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