Skip to content

Instantly share code, notes, and snippets.

@ynkdir
Last active December 23, 2015 04:19
Show Gist options
  • Save ynkdir/6579203 to your computer and use it in GitHub Desktop.
Save ynkdir/6579203 to your computer and use it in GitHub Desktop.
// http://www.tatapa.org/~takuo/input_subsystem/input_subsystem.html
// virtual key event
// sudo sh -c "./a.out keycode > /dev/input/eventX"
// 30 == KEY_A
// 41 == KEY_GRAVE (zenkaku hankaku)
#include <linux/input.h> // see for keycode constant KEY_XXX
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define KEYRELEASE 0
#define KEYPRESS 1
void write_key_event(int code, int value, int fd)
{
struct input_event key_event;
gettimeofday(&key_event.time, NULL);
key_event.type = EV_KEY;
key_event.code = code;
key_event.value = value;
write(fd, &key_event, sizeof(key_event));
}
int main(int argc, char **argv)
{
int i;
int code;
for (i = 1; i < argc; ++i) {
sscanf(argv[i], "%i", &code);
write_key_event(code, KEYPRESS, STDOUT_FILENO);
write_key_event(code, KEYRELEASE, STDOUT_FILENO);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment