need help to generate keystrokes into existing application in Linux environment using C++

前端 未结 1 1385
名媛妹妹
名媛妹妹 2021-01-25 11:13

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 Wind

相关标签:
1条回答
  • 2021-01-25 12:02

    What you want is create and initialize XKeyEvent struct and send it with XSendEvent.

    Be sure to check man xkeyevent and man xsendevent

    From 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;
    

    To get key keycodes, check /usr/include/X11/keysymdef.h ur just use xev

    I found a brief introduction for you.

    (Edit: It seems someone solved it already :))

    0 讨论(0)
提交回复
热议问题