Basic keylogger in Go (no C deps)
Branch: master
Clone or download
MarinX Merge pull request #5 from MarinX/handle-error-on-read
Handle error when reading/parsing from file
Latest commit bf368a5 Feb 15, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example 2019 Rewrite library Feb 2, 2019
.gitignore Initial commit Sep 27, 2015
.travis.yml 2019 Rewrite library Feb 2, 2019
LICENSE Initial commit Sep 27, 2015
README.md 2019 Rewrite library Feb 2, 2019
doc.go 2019 Rewrite library Feb 2, 2019
input_event.go 2019 Rewrite library Feb 2, 2019
keylogger.go Handle error when reading/parsing from file Feb 14, 2019
keylogger_test.go Handle error when reading/parsing from file Feb 14, 2019
keymapper.go 2019 Rewrite library Feb 2, 2019

README.md

Keylogger

Capture global keyboard events on Linux

Build Status GoDoc License MIT

Notes

  • Only Linux based
  • Need root privilages

Installation

go get github.com/MarinX/keylogger

Getting started

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"

/sys/class/input/event[0-255]/device/name

and returns the file event path if found

/dev/input/event2

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

keylogger.New("/dev/input/event2")

Getting keypress

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

keylogger.EvKey

Once you get desire event, there is a helper to parse code into human readable key.

event.KeyString()

NOTE

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()

Example

You can find a example script in example/main.go

Running tests

No magic, just run

go test -v

Creating key sniffer (needs update)

License

This library is under the MIT License

Donate

I don't drink beer, so energy drink will do :)

BTC: 19AtHE6dgKX3R9vJSCSKRyF1saexLcBRep