you can find the device location by running libinput list-devices, and by looking for your keyboard there, or find your keyboard device in /proc/bus/input/devices. And run this with root.
I didn't write this just because I wanted to write a keylogger. That is one of the reasons, but the main objective was to learn more about /dev/input/, and I did, I learned more about ioctl and bitmasks too. Originally I wanted to write a keylogger that sends the characters to another computer, but why should I waste time writing a server client model for no reason. Then for a while I was trying to figure out how to find the keyboard's device myself(that's how I learned more about ioctl and bitmasks) but then i realised I dont care
also i forgot to close the dev's file descriptor, anyone who wants to do it can make that fd global, then add a close call to the cleanup() function, and make sure fd is opened after the fork call. Im too lazy to do it.