37 lines
598 B
Go
37 lines
598 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
hook "github.com/robotn/gohook"
|
|
)
|
|
|
|
func main() {
|
|
hook.Register(hook.KeyDown, []string{
|
|
"esc",
|
|
}, func(e hook.Event) {
|
|
fmt.Println("=========", e.String())
|
|
// hook.End()
|
|
})
|
|
hook.Register(hook.KeyDown, []string{
|
|
"1",
|
|
}, func(e hook.Event) {
|
|
fmt.Println(
|
|
"按键 : ", string(e.Keychar),
|
|
"触发时间 : ", time.Now().Format("2006-01-02 15:04:05"))
|
|
//hook.End()
|
|
})
|
|
|
|
for {
|
|
fmt.Println("--- Please press esc ---")
|
|
s := hook.Start()
|
|
<-hook.Process(s)
|
|
|
|
ok := hook.AddEvents("esc")
|
|
if ok {
|
|
fmt.Println("pressed esc...")
|
|
}
|
|
}
|
|
}
|