mirror of
https://github.com/robotn/gohook.git
synced 2025-01-19 06:06:41 +08:00
add more examples code and add log print
This commit is contained in:
parent
419a0340b3
commit
6ca4fbe91a
@ -6,8 +6,25 @@ import (
|
|||||||
hook "github.com/robotn/gohook"
|
hook "github.com/robotn/gohook"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func addEvent() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
// hook listen and return values using detailed examples
|
// hook listen and return values using detailed examples
|
||||||
func add() {
|
func add() {
|
||||||
|
fmt.Println("hook add...")
|
||||||
s := hook.Start()
|
s := hook.Start()
|
||||||
defer hook.End()
|
defer hook.End()
|
||||||
|
|
||||||
@ -27,6 +44,7 @@ func add() {
|
|||||||
|
|
||||||
// base hook example
|
// base hook example
|
||||||
func base() {
|
func base() {
|
||||||
|
fmt.Println("hook start...")
|
||||||
evChan := hook.Start()
|
evChan := hook.Start()
|
||||||
defer hook.End()
|
defer hook.End()
|
||||||
|
|
||||||
@ -36,6 +54,8 @@ func base() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
addEvent()
|
||||||
|
|
||||||
base()
|
base()
|
||||||
|
|
||||||
add()
|
add()
|
||||||
|
Loading…
Reference in New Issue
Block a user