gpt4 book ai didi

keyboard-events - 在 Xlib 中模拟 CAPS LOCK 按下

转载 作者:行者123 更新时间:2023-12-02 19:09:51 25 4
gpt4 key购买 nike

如何使用 Xlib 模拟大写锁定开关的按下?

最佳答案

#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>

// Function: Click Key (press and release key)
void click_key( Display* p_display , KeyCode keycode ) {

XTestFakeKeyEvent( p_display , keycode , True , 0 ); // key press event
XTestFakeKeyEvent( p_display , keycode , False , 0 ); // key release event
XFlush( p_display );

return;
}

// Main
int main() {

Display* p_display = XOpenDisplay( NULL );
KeySym keysym = XK_VoidSymbol;
KeyCode keycode = NoSymbol;

keysym = XK_Caps_Lock;
keycode = XKeysymToKeycode( p_display , keysym );

click_key( p_display , keycode ); // activates CapsLock
click_key( p_display , keycode ); // deactivates CapsLock

XCloseDisplay( p_display );
return 0;
}

关于keyboard-events - 在 Xlib 中模拟 CAPS LOCK 按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3547241/

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