Capture global keyboard events on Linux
- Only Linux based
- Need root privilages
go get github.com/MarinX/keylogger
Finding keyboard device
There is a helper on finding the keyboard.
keyboard := keylogger.FindKeyboardDevice()
Which goes through each file device name to find keyword "keyboard"
and returns the file event path if found
If the function returns empty string, you will need to cat each device name and get the event number. If you know already, you can easily pass it to constructor
Once the keylogger returns channel event, you can switch by event code as described in input_event.go For start, you can listen on keyboard state change
Once you get desire event, there is a helper to parse code into human readable key.
If you listen on keyboard state change, it will return double results. This is because pressing and releasing the key are 2 different state change. There is a helper function which you can call to see which type of state change happend
// returns true if key on keyboard is pressed event.KeyPress() // returns true if key on keyboard is released event.KeyRelease()
You can find a example script in
No magic, just run
go test -v
Creating key sniffer (needs update)
This library is under the MIT License
I don't drink beer, so energy drink will do :)