0

Right now I'm reading directly from /dev/input/eventX. Is there some library or api that would convert the byte stream for me? Below is the code I'm running, sample input and output.

int main (void)
{
    struct input_event ev;
    int fd, rd;

    //Open Device
    if ((fd = open ("/dev/input/event0", O_RDONLY)) == -1){
        printf ("not a vaild device.\n");
        return -1;
    }

    while (1){

        memset((void*)&ev, 0, sizeof(ev));

        rd = read (fd, (void*)&ev, sizeof(ev));

        if (rd > 0 && ev.type==1){
            printf("value: %d, code: %d\n", ev.value, ev.code);
        }
    }

If I type

XAL4

I get:

value: 1, code: 42
value: 1, code: 45
value: 0, code: 42
value: 0, code: 45
value: 1, code: 42
value: 1, code: 30
value: 0, code: 42
value: 0, code: 30
value: 1, code: 42
value: 1, code: 38
value: 0, code: 42
value: 0, code: 38
value: 1, code: 5
value: 0, code: 5

Using the header, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/input-event-codes.h

I know that the key sequence is:

KEY_DOWN: SHIFT 
KEY_DOWN: X 
KEY_UP: SHIFT 
KEY_UP: X 
KEY_DOWN: SHIFT 
KEY_DOWN: A 
KEY_UP: SHIFT 
KEY_UP: A
KEY_DOWN: SHIFT 
KEY_DOWN: L 
KEY_UP: SHIFT 
KEY_UP: L
KEY_DOWN: 4 
KEY_UP: 4

Is there a library or api that would convert this to raw ascii for me?

willpnw
  • 755
  • 1
  • 6
  • 23
  • Sure, have you [tried searching for one](https://www.google.com/search?q=c%2B%2B+linux+keylogger&rlz=1C1NHXL_enUS815US815&oq=c%2B%2B+linux+keylogger&aqs=chrome..69i57.4399j0j7&sourceid=chrome&ie=UTF-8) already? The first few results look promising... – scohe001 Nov 20 '19 at 21:45
  • Rather than raw X events, maybe you want to use a library like ncurses. – stark Nov 20 '19 at 22:11

0 Answers0