I am running Fedora linux and I am trying to simulate key strokes in the browser (specifically the arrow keys). What is the best way to do this in C
            Asked
            
        
        
            Active
            
        
            Viewed 446 times
        
    1 Answers
2
            You can do this with the XTest extesion, a simple example:
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/extensions/XTest.h>
#include <unistd.h>
static void SendKey (Display *disp, KeySym keysym)
{
  KeyCode keycode = 0;
  keycode = XKeysymToKeycode (disp, keysym);
  if (keycode == 0) return;
  XTestGrabControl (disp, True);
  XTestFakeKeyEvent (disp, keycode, True, 0);
  XTestFakeKeyEvent (disp, keycode, False, 0);
  XSync (disp, False);
  XTestGrabControl (disp, False);
}
/* Main Function */
int main ()
{
  Display *disp = XOpenDisplay (NULL);
  /* A, B */
  SendKey (disp, XK_A);
  SendKey (disp, XK_B);
  return 0;
}
(adapted from this link)
        Flexo
        
- 87,323
 - 22
 - 191
 - 272