2017-02-06 16:55:01 +08:00
|
|
|
# gohook
|
|
|
|
|
2019-12-07 14:27:27 -04:00
|
|
|
[](https://github.com/robotn/gohook/commits/master)
|
2019-02-19 10:34:55 -04:00
|
|
|
[](https://circleci.com/gh/robotn/gohook)
|
|
|
|

|
|
|
|
[](https://goreportcard.com/report/github.com/robotn/gohook)
|
|
|
|
[](https://godoc.org/github.com/robotn/gohook)
|
2018-09-17 14:09:59 -04:00
|
|
|
<!-- This is a work in progress. -->
|
2018-09-04 15:25:08 -04:00
|
|
|
|
|
|
|
```Go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-02-19 10:34:55 -04:00
|
|
|
|
2020-09-07 10:27:44 -04:00
|
|
|
hook "github.com/robotn/gohook"
|
2018-09-04 15:25:08 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-05-29 10:24:17 -04:00
|
|
|
add()
|
|
|
|
|
|
|
|
low()
|
|
|
|
}
|
|
|
|
|
|
|
|
func add() {
|
2020-05-28 10:31:52 -04:00
|
|
|
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("w")
|
|
|
|
})
|
|
|
|
|
|
|
|
s := hook.Start()
|
|
|
|
<-hook.Process(s)
|
2020-05-29 10:24:17 -04:00
|
|
|
}
|
2020-05-28 10:31:52 -04:00
|
|
|
|
2020-05-29 10:24:17 -04:00
|
|
|
func low() {
|
2019-02-19 11:31:25 -03:00
|
|
|
EvChan := hook.Start()
|
|
|
|
defer hook.End()
|
2020-05-29 10:24:17 -04:00
|
|
|
|
2019-02-19 11:31:25 -03:00
|
|
|
for ev := range EvChan {
|
2019-07-28 14:12:01 -04:00
|
|
|
fmt.Println("hook: ", ev)
|
2018-09-04 15:25:08 -04:00
|
|
|
}
|
|
|
|
}
|
2020-05-29 10:24:17 -04:00
|
|
|
|
2019-02-19 10:34:55 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
Based on [libuiohook](https://github.com/kwhat/libuiohook).
|