Created
July 4, 2010 05:34
-
-
Save errzey/463175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
process_keystroke(int fd, short which, keyboard_t *kb) | |
{ | |
struct input_event input_event; | |
ssize_t bytes_read; | |
char key; | |
bytes_read = read(fd, &input_event, sizeof(struct input_event)); | |
if (bytes_read != sizeof(struct input_event)) { | |
fprintf(stderr, "[*] error reading device, ABORTING!\n"); | |
return; | |
} | |
/* make sure this is a keypress of some sort */ | |
if (input_event.type != EV_KEY) { | |
return; | |
} | |
/* look for some things that may modify the next stroke */ | |
switch (input_event.code) { | |
case KEY_RIGHTSHIFT: | |
case KEY_LEFTSHIFT: | |
kb->shift_mod = input_event.value; | |
return; | |
case KEY_RIGHTCTRL: | |
case KEY_LEFTCTRL: | |
/* I don't really care about ctrl chars */ | |
return; | |
case KEY_CAPSLOCK: | |
if (input_event.value == 1) { | |
if (kb->caps_mod) { | |
kb->caps_mod = 0; | |
} else { | |
kb->caps_mod = 1; | |
} | |
} | |
return; | |
} | |
if (input_event.value != 1) { | |
return; | |
} | |
if (input_event.code > sizeof(lowercase_map)) { | |
return; | |
} | |
if (kb->shift_mod) { | |
key = uppercase_map[input_event.code]; | |
if (kb->caps_mod) { | |
key = tolower(key); | |
} | |
} else { | |
key = lowercase_map[input_event.code]; | |
if (kb->caps_mod) { | |
key = toupper(key); | |
} | |
} | |
fprintf(stdout, "%c", key ? key : 0); | |
fflush(stdout); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment