-1

I've been trying to make a keylogger on Ubuntu 16.04LTS for a while now, and this is what I have so far:

#include <stdio.h>
#include <fcntl.h>
#include <linux/input.h>
#include <stdbool.h>

int main()
{
        char devname[] = "/dev/input/event0";
        int device = open(devname, O_RDONLY);
        struct input_event ev; 
        bool logging = true;

        while(logging)
        {
                if (read(device,&ev, sizeof(ev)) >= 0){ 
                        printf("Key: %i State: %i Type: %i\n",ev.code,ev.value,ev.type);
                }
        }

}

However when I compile and run it (gcc), it does not output anything! I've tried every device listed in /dev/input/by-id andthensome,but nothing seems to work.

When I compile the code using GCC, I get the warning:

keylogger.c: In function ‘main’:
keylogger.c:15:7: warning: implicit declaration of function ‘read’ [-Wimplicit-function-declaration]
   if (read(device,&ev, sizeof(ev)) >= 0){       
       ^

Which I have no idea if this has to do with the functionality of the program.

Any help is appreciated! Thanks!

Logan Darby
  • 145
  • 16

1 Answers1

1

I figured it out, it was a simple matter of not having superuser permissions. I excecuted the file using sudo and now everything is fine.

Logan Darby
  • 145
  • 16