Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marinx/keylogger
Basic keylogger in Go (no C deps)
https://github.com/marinx/keylogger
go golang keylogger linux
Last synced: 1 day ago
JSON representation
Basic keylogger in Go (no C deps)
- Host: GitHub
- URL: https://github.com/marinx/keylogger
- Owner: MarinX
- License: mit
- Created: 2015-09-27T10:17:49.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-06-20T10:58:46.000Z (5 months ago)
- Last Synced: 2024-11-07T11:52:59.102Z (9 days ago)
- Topics: go, golang, keylogger, linux
- Language: Go
- Size: 15.6 KB
- Stars: 236
- Watchers: 9
- Forks: 59
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Keylogger
Capture global keyboard events on Linux
[![Build Status](https://travis-ci.org/MarinX/keylogger.svg?branch=master)](https://travis-ci.org/MarinX/keylogger)
[![GoDoc](https://godoc.org/github.com/MarinX/keylogger?status.svg)](https://godoc.org/github.com/MarinX/keylogger)
[![License MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE)## Notes
* Only Linux based
* Need root privilages## Installation
```sh
go get github.com/MarinX/keylogger
```## Getting started
### Finding keyboard device
There is a helper on finding the keyboard.
```go
keyboard := keylogger.FindKeyboardDevice()
```
Which goes through each file device name to find keyword "keyboard"
```sh
/sys/class/input/event[0-255]/device/name
```
and returns the file event path if found
```sh
/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
```sh
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](https://github.com/MarinX/keylogger/blob/master/input_event.go)
For start, you can listen on keyboard state change
```go
keylogger.EvKey
```
Once you get desire event, there is a helper to parse code into human readable key.
```go
event.KeyString()
```### Writing keypress
Best way is to open an text editor and see how keyboard will react
There are 2 methods:
```go
func (k *KeyLogger) WriteOnce(key string) error
```
and
```go
func (k *KeyLogger) Write(direction KeyEvent, key string) error
```
`WriteOnce` method simulates single key press, eg: press and release letter M`Write` writes to keyboard and sync the event.
This will keep the key pressed or released until you call another write with other direction
eg, if the key is "A" and direction is press, on UI, you will see "AAAAA..." until you stop with releaseProbably you want to use `WriteOnce` method
**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
```go
// 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
```sh
go test -v
```## Creating key sniffer (needs update)
* [sniffing global keyboard events in go](https://medium.com/@marin.basic02/sniffing-global-keyboard-events-in-go-e5497e618192/)## License
This library is under the MIT License