0

I am looking at creating a program that rolls 5 random numbers, and depending on what those numbers are it press 5 different keys.

I know how to generate 5 different random numbers, but how can I have it simulate key presses so it works in a different application? I'm going to use it to randomly buy stuff in a game. I read that it's Keypress() but I'm not sure what the syntax is. I don't need anything other than the context to use the command in

Thanks!

1 Answers1

3

In linux, you can Use X11 like this

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

Display *display;
unsigned int keycode;
display = XOpenDisplay(NULL);
...
keycode = XKeysymToKeycode(display, XK_Pause);
XTestFakeKeyEvent(display, keycode, True, 0);
XFlush(display);

In compilation link you must use -lX11 -lXtst. In windows, you can use send_input

dsapandora
  • 104
  • 7