gohook/test/main.go

41 lines
795 B
Go
Raw Normal View History

2017-02-06 16:55:01 +08:00
package main
import (
"fmt"
"time"
2018-09-05 03:25:08 +08:00
2019-02-19 22:34:55 +08:00
"github.com/robotn/gohook"
2017-02-06 16:55:01 +08:00
)
func main() {
s := hook.Start()
defer hook.End()
2019-02-19 23:32:48 +08:00
2019-02-19 22:34:55 +08:00
tout := time.After(time.Hour * 2)
done := false
for !done {
select {
case i := <-s:
if i.Kind >= hook.KeyDown && i.Kind <= hook.KeyUp {
if i.Keychar == 'q' {
tout = time.After(0)
}
2019-02-19 23:32:48 +08:00
2019-02-19 22:34:55 +08:00
fmt.Printf("%v key: %c:%v\n", i.Kind, i.Keychar, i.Rawcode)
} else if i.Kind >= hook.MouseDown && i.Kind < hook.MouseWheel {
//fmt.Printf("x: %v, y: %v, button: %v\n", i.X, i.Y, i.Button)
2019-02-19 22:34:55 +08:00
} else if i.Kind == hook.MouseWheel {
//fmt.Printf("x: %v, y: %v, button: %v, wheel: %v, rotation: %v\n", i.X, i.Y, i.Button,i.Amount,i.Rotation)
} else {
2019-02-19 22:34:55 +08:00
fmt.Printf("%+v\n", i)
}
2019-02-19 23:32:48 +08:00
case <-tout:
fmt.Print("Done.")
done = true
break
}
2017-02-06 16:55:01 +08:00
}
2017-02-06 16:55:01 +08:00
}