2017-02-06 16:55:01 +08:00
|
|
|
# gohook
|
|
|
|
|
2019-12-08 02:27:27 +08:00
|
|
|
[![Build Status](https://github.com/robotn/gohook/workflows/Go/badge.svg)](https://github.com/robotn/gohook/commits/master)
|
2019-02-19 22:34:55 +08:00
|
|
|
[![CircleCI Status](https://circleci.com/gh/robotn/gohook.svg?style=shield)](https://circleci.com/gh/robotn/gohook)
|
|
|
|
![Appveyor](https://ci.appveyor.com/api/projects/status/github/robotn/gohook?branch=master&svg=true)
|
|
|
|
[![Go Report Card](https://goreportcard.com/badge/github.com/robotn/gohook)](https://goreportcard.com/report/github.com/robotn/gohook)
|
|
|
|
[![GoDoc](https://godoc.org/github.com/robotn/gohook?status.svg)](https://godoc.org/github.com/robotn/gohook)
|
2018-09-18 02:09:59 +08:00
|
|
|
<!-- This is a work in progress. -->
|
2018-09-05 03:25:08 +08:00
|
|
|
|
2021-12-25 02:05:52 +08:00
|
|
|
## 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:
|
|
|
|
|
2018-09-05 03:25:08 +08:00
|
|
|
```Go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-02-19 22:34:55 +08:00
|
|
|
|
2020-09-07 22:27:44 +08:00
|
|
|
hook "github.com/robotn/gohook"
|
2018-09-05 03:25:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-05-29 22:24:17 +08:00
|
|
|
add()
|
|
|
|
|
|
|
|
low()
|
|
|
|
}
|
|
|
|
|
|
|
|
func add() {
|
2020-05-28 22:31:52 +08: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 22:24:17 +08:00
|
|
|
}
|
2020-05-28 22:31:52 +08:00
|
|
|
|
2020-05-29 22:24:17 +08:00
|
|
|
func low() {
|
2021-10-17 00:01:40 +08:00
|
|
|
evChan := hook.Start()
|
2019-02-19 22:31:25 +08:00
|
|
|
defer hook.End()
|
2020-05-29 22:24:17 +08:00
|
|
|
|
2021-10-17 00:01:40 +08:00
|
|
|
for ev := range evChan {
|
2019-07-29 02:12:01 +08:00
|
|
|
fmt.Println("hook: ", ev)
|
2018-09-05 03:25:08 +08:00
|
|
|
}
|
|
|
|
}
|
2020-05-29 22:24:17 +08:00
|
|
|
|
2019-02-19 22:34:55 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
Based on [libuiohook](https://github.com/kwhat/libuiohook).
|