https://github.com/robotn/gohook
GoHook, Go global keyboard and mouse listener hook
https://github.com/robotn/gohook
go golang hook keyboard listener mouse-events
Last synced: 3 months ago
JSON representation
GoHook, Go global keyboard and mouse listener hook
- Host: GitHub
- URL: https://github.com/robotn/gohook
- Owner: robotn
- License: mit
- Created: 2017-01-21T08:52:05.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-02-08T23:46:59.000Z (5 months ago)
- Last Synced: 2025-02-09T00:23:44.404Z (5 months ago)
- Topics: go, golang, hook, keyboard, listener, mouse-events
- Language: C
- Homepage:
- Size: 195 KB
- Stars: 342
- Watchers: 11
- Forks: 45
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome - robotn/gohook - events pushed_at:2025-06 star:0.4k fork:0.0k GoHook, Go global keyboard and mouse listener hook (C)
README
# gohook
[](https://github.com/robotn/gohook/commits/master)
[](https://circleci.com/gh/robotn/gohook)

[](https://goreportcard.com/report/github.com/robotn/gohook)
[](https://godoc.org/github.com/robotn/gohook)## Requirements (Linux):
[Robotgo-requirements-event](https://github.com/go-vgo/robotgo#requirements)
## Install:
With Go module support (Go 1.11+), just import:
```go
import "github.com/robotn/gohook"
```## Examples:
```Go
package mainimport (
"fmt"hook "github.com/robotn/gohook"
)func main() {
add()low()
}func add() {
fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
hook.Register(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
fmt.Println("ctrl-shift-q")
hook.End()
})fmt.Println("--- Please press w---")
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
fmt.Println("keyDown: ", "w")
})hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) {
fmt.Println("keyUp: ", "w")
})s := hook.Start()
<-hook.Process(s)
}func low() {
evChan := hook.Start()
defer hook.End()for ev := range evChan {
fmt.Println("hook: ", ev)
}
}```
Based on [libuiohook](https://github.com/kwhat/libuiohook).