mirror of
https://github.com/robotn/gohook.git
synced 2024-11-21 18:36:51 +08:00
add example and update code style
This commit is contained in:
parent
1da30b1d41
commit
9fa8b6c408
@ -18,6 +18,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
EvChan := hook.Start()
|
EvChan := hook.Start()
|
||||||
defer hook.End()
|
defer hook.End()
|
||||||
|
|
||||||
for ev := range EvChan {
|
for ev := range EvChan {
|
||||||
fmt.Println(ev)
|
fmt.Println(ev)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ environment:
|
|||||||
PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH%
|
PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH%
|
||||||
# - COMPILER: MINGW_W64
|
# - COMPILER: MINGW_W64
|
||||||
# ARCHITECTURE: x64
|
# ARCHITECTURE: x64
|
||||||
GOVERSION: 1.11.4
|
GOVERSION: 1.11.5
|
||||||
# GOPATH: c:\gopath
|
# GOPATH: c:\gopath
|
||||||
|
|
||||||
# scripts that run after cloning repository
|
# scripts that run after cloning repository
|
||||||
|
@ -34,7 +34,9 @@ void pollEv(){
|
|||||||
if (events == NULL) return;
|
if (events == NULL) return;
|
||||||
for (;eb_chan_buf_len(events)!=0;) {
|
for (;eb_chan_buf_len(events)!=0;) {
|
||||||
char* tmp;
|
char* tmp;
|
||||||
if( eb_chan_try_recv(events,(const void**) &tmp) == eb_chan_res_ok ){
|
if (eb_chan_try_recv(events, (const void**) &tmp)
|
||||||
|
== eb_chan_res_ok) {
|
||||||
|
// send a char
|
||||||
go_send(tmp);
|
go_send(tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
} else {
|
} else {
|
||||||
|
40
example/main.go
Normal file
40
example/main.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/robotn/gohook"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func base() {
|
||||||
|
EvChan := hook.Start()
|
||||||
|
defer hook.End()
|
||||||
|
|
||||||
|
for ev := range EvChan {
|
||||||
|
fmt.Println(ev)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
base()
|
||||||
|
|
||||||
|
add()
|
||||||
|
}
|
@ -175,6 +175,7 @@ var (
|
|||||||
251: "unlock trackpad (Chrome/Edge)",
|
251: "unlock trackpad (Chrome/Edge)",
|
||||||
255: "toggle touchpad",
|
255: "toggle touchpad",
|
||||||
}
|
}
|
||||||
|
|
||||||
keytoraw = map[string]uint16{
|
keytoraw = map[string]uint16{
|
||||||
"error": 0,
|
"error": 0,
|
||||||
"break": 3,
|
"break": 3,
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
s := hook.Start()
|
s := hook.Start()
|
||||||
defer hook.End()
|
defer hook.End()
|
||||||
|
|
||||||
tout := time.After(time.Hour * 2)
|
tout := time.After(time.Hour * 2)
|
||||||
done := false
|
done := false
|
||||||
for !done {
|
for !done {
|
||||||
@ -19,6 +20,7 @@ func main() {
|
|||||||
if i.Keychar == 'q' {
|
if i.Keychar == 'q' {
|
||||||
tout = time.After(0)
|
tout = time.After(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%v key: %c:%v\n", i.Kind, i.Keychar, i.Rawcode)
|
fmt.Printf("%v key: %c:%v\n", i.Kind, i.Keychar, i.Rawcode)
|
||||||
} else if i.Kind >= hook.MouseDown && i.Kind < hook.MouseWheel {
|
} 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)
|
//fmt.Printf("x: %v, y: %v, button: %v\n", i.X, i.Y, i.Button)
|
||||||
@ -27,6 +29,7 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Printf("%+v\n", i)
|
fmt.Printf("%+v\n", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-tout:
|
case <-tout:
|
||||||
fmt.Print("Done.")
|
fmt.Print("Done.")
|
||||||
done = true
|
done = true
|
||||||
|
Loading…
Reference in New Issue
Block a user