gohook/example/main.go

43 lines
492 B
Go
Raw Normal View History

2019-02-19 23:32:48 +08:00
package main
import (
"fmt"
2019-10-11 01:11:32 +08:00
hook "github.com/robotn/gohook"
2019-02-19 23:32:48 +08:00
)
2019-10-11 01:11:32 +08:00
// hook listen and return values using detailed examples
2019-02-19 23:32:48 +08:00
func add() {
s := hook.Start()
defer hook.End()
ct := false
for {
i := <-s
if i.Kind == hook.KeyHold && i.Rawcode == 59 {
ct = true
}
if ct && i.Rawcode == 12 {
break
}
}
}
2019-10-11 01:11:32 +08:00
// base hook example
2019-02-19 23:32:48 +08:00
func base() {
2019-10-31 23:08:50 +08:00
evChan := hook.Start()
2019-02-19 23:32:48 +08:00
defer hook.End()
2019-10-31 23:08:50 +08:00
for ev := range evChan {
2019-07-29 02:12:01 +08:00
fmt.Println("hook: ", ev)
2019-02-19 23:32:48 +08:00
}
}
func main() {
base()
add()
}