需要帮助以使用C ++在Linux环境中生成对现有应用程序的击键 [英] need help to generate keystrokes into existing application in Linux environment using C++
问题描述
我需要帮助以在LINUX环境中的现有应用程序中生成击键. 我完全知道,Dev C ++中有一些库可以完全满足我的要求,但是在Windows中,我在Linux中需要类似的库.我在Google上搜索了很多,但找不到任何解决方案. 以下是Dev C ++库的代码,我想要Linux中的类似代码.任何帮助,建议,批评都是最欢迎的.
I need help to generate keystrokes in my existing application in LINUX environment. I am fully aware that there are libraries in Dev C++ which do exactly what I want but in Windows and I need something like that in Linux. I have googled a lot, but could not able to find any solution. Below are the code of Dev C++ library and I want something like that in Linux. Any help, suggestion , criticism are most welcome.
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
Thanks and regards, SamPrat
推荐答案
您想要的是创建并初始化XKeyEvent
结构,并使用XSendEvent
发送它.
What you want is create and initialize XKeyEvent
struct and send it with 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
To get key keycodes, check /usr/include/X11/keysymdef.h
ur just use xev
我为您找到了简要介绍.
(似乎有人解决了已经:))
这篇关于需要帮助以使用C ++在Linux环境中生成对现有应用程序的击键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!