我需要帮助在LINUX环境中的现有应用程序中生成击键。 我完全清楚Dev C ++中有些库可以完全满足我的需求,但在Windows中我需要在Linux中使用类似的东西。我google了很多,但无法找到任何解决方案。 下面是Dev C ++库的代码,我想在Linux中使用类似的东西。任何帮助,建议和批评都是最受欢迎的。
void GenerateKey(int vk , BOOL bExtended)
{
KEYBDINPUT kb = {0};
INPUT Input = {0};
// generate down
if(bExtended)
kb.dwFlags = KEYEVENTF_EXTENDEDKEY;
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1, &Input, sizeof(Input));
// generate up
::ZeroMemory(&kb, sizeof(KEYBDINPUT));
::ZeroMemory(&Input, sizeof(INPUT));
kb.dwFlags = KEYEVENTF_KEYUP;
if(bExtended)
kb.dwFlags |= KEYEVENTF_EXTENDEDKEY;
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1, &Input, sizeof(Input));
}
谢谢和问候, SamPrat
答案 0 :(得分:1)
您想要的是创建和初始化XKeyEvent
结构并使用XSendEvent
发送它。
务必检查man xkeyevent
和man xsendevent
来自man xkeyevent
:
typedef struct {
int type; /* KeyPress or KeyRelease */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* ``event'' window it is reported relative to */
Window root; /* root window that the event occurred on */
Window subwindow; /* child window */
Time time; /* milliseconds */
int x, y; /* pointer x, y coordinates in event window */
int x_root, y_root; /* coordinates relative to root */
unsigned int state; /* key or button mask */
unsigned int keycode; /* detail */
Bool same_screen; /* same screen flag */
} XKeyEvent;
要获取关键密码,请检查/usr/include/X11/keysymdef.h
,然后使用xev
我找到了brief introduction。
(编辑:似乎someone solved it已经:))