|
1 |
| -# KeyLogger |
| 1 | +# Keylogger |
2 | 2 |
|
3 |
| -# Description |
4 | 3 | Capture global keyboard events on Linux
|
5 | 4 |
|
6 |
| -# Installation |
7 |
| - go get github.com/MarinX/keylogger |
8 |
| -# Notes |
| 5 | +[](https://travis-ci.org/MarinX/keylogger) |
| 6 | +[](https://godoc.org/github.com/MarinX/keylogger) |
| 7 | +[](LICENSE) |
| 8 | + |
| 9 | +## Notes |
9 | 10 | * Only Linux based
|
10 | 11 | * Need root privilages
|
11 | 12 |
|
| 13 | +## Installation |
| 14 | +```sh |
| 15 | +go get github.com/MarinX/keylogger |
| 16 | +``` |
12 | 17 |
|
13 |
| -# Example |
14 |
| - package main |
15 |
| - |
16 |
| - import ( |
17 |
| - "fmt" |
18 |
| - "github.com/MarinX/keylogger" |
19 |
| - ) |
| 18 | +## Getting started |
20 | 19 |
|
21 |
| - func main() { |
22 |
| - devs, err := keylogger.NewDevices() |
23 |
| - if err != nil { |
24 |
| - fmt.Println(err) |
25 |
| - return |
26 |
| - } |
| 20 | +### Finding keyboard device |
| 21 | +There is a helper on finding the keyboard. |
| 22 | +```go |
| 23 | + keyboard := keylogger.FindKeyboardDevice() |
| 24 | +``` |
| 25 | +Which goes through each file device name to find keyword "keyboard" |
| 26 | +```sh |
| 27 | +/sys/class/input/event[0-255]/device/name |
| 28 | +``` |
| 29 | +and returns the file event path if found |
| 30 | +```sh |
| 31 | +/dev/input/event2 |
| 32 | +``` |
| 33 | +If the function returns empty string, you will need to cat each device name and get the event number. |
| 34 | +If you know already, you can easily pass it to constructor |
| 35 | +```sh |
| 36 | +keylogger.New("/dev/input/event2") |
| 37 | +``` |
27 | 38 |
|
28 |
| - for _, val := range devs { |
29 |
| - fmt.Println("Id->", val.Id, "Device->", val.Name) |
30 |
| - } |
| 39 | +### Getting keypress |
| 40 | +Once the keylogger returns channel event, you can switch by event code as described in [input_event.go](https://github.com/MarinX/keylogger/blob/master/input_event.go) |
| 41 | +For start, you can listen on keyboard state change |
| 42 | +```go |
| 43 | +keylogger.EvKey |
| 44 | +``` |
| 45 | +Once you get desire event, there is a helper to parse code into human readable key. |
| 46 | +```go |
| 47 | +event.KeyString() |
| 48 | +``` |
| 49 | +**NOTE** |
31 | 50 |
|
32 |
| - //keyboard device file, on your system it will be diffrent! |
33 |
| - rd := keylogger.NewKeyLogger(devs[3]) |
| 51 | +If you listen on keyboard state change, it will return __double__ results. |
| 52 | +This is because pressing and releasing the key are 2 different state change. |
| 53 | +There is a helper function which you can call to see which type of state change happend |
| 54 | +```go |
| 55 | +// returns true if key on keyboard is pressed |
| 56 | +event.KeyPress() |
34 | 57 |
|
35 |
| - in, err := rd.Read() |
36 |
| - if err != nil { |
37 |
| - fmt.Println(err) |
38 |
| - return |
39 |
| - } |
| 58 | +// returns true if key on keyboard is released |
| 59 | +event.KeyRelease() |
| 60 | +``` |
40 | 61 |
|
41 |
| - for i := range in { |
| 62 | +### Example |
| 63 | +You can find a example script in ```example/main.go``` |
42 | 64 |
|
43 |
| - //we only need keypress |
44 |
| - if i.Type == keylogger.EV_KEY { |
45 |
| - fmt.Println(i.KeyString()) |
46 |
| - } |
47 |
| - } |
48 |
| - } |
| 65 | +### Running tests |
| 66 | +No magic, just run |
| 67 | +```sh |
| 68 | +go test -v |
| 69 | +``` |
49 | 70 |
|
50 |
| -# Creating key sniffer |
51 |
| -* [sniffing global keyboard eventy in go](https://medium.com/@marin.basic02/sniffing-global-keyboard-events-in-go-e5497e618192/) |
| 71 | +## Creating key sniffer (needs update) |
| 72 | +* [sniffing global keyboard events in go](https://medium.com/@marin.basic02/sniffing-global-keyboard-events-in-go-e5497e618192/) |
52 | 73 |
|
53 | 74 |
|
54 |
| -# License |
| 75 | +## License |
55 | 76 | This library is under the MIT License
|
56 |
| -# Author |
57 |
| -Marin Basic |
| 77 | + |
| 78 | +## Donate |
| 79 | +I don't drink beer, so energy drink will do :) |
| 80 | + |
| 81 | +BTC: 19AtHE6dgKX3R9vJSCSKRyF1saexLcBRep |
0 commit comments