diff --git a/README.md b/README.md index 584bd89..251729c 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ import ( func main() { EvChan := hook.Start() defer hook.End() + for ev := range EvChan { fmt.Println(ev) } diff --git a/appveyor.yml b/appveyor.yml index abe8c2a..7d8bfb8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,7 +34,7 @@ environment: PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH% # - COMPILER: MINGW_W64 # ARCHITECTURE: x64 - GOVERSION: 1.11.4 + GOVERSION: 1.11.5 # GOPATH: c:\gopath # scripts that run after cloning repository diff --git a/event/goEvent.h b/event/goEvent.h index a5ca1e0..21ec2ae 100644 --- a/event/goEvent.h +++ b/event/goEvent.h @@ -34,7 +34,9 @@ void pollEv(){ if (events == NULL) return; for (;eb_chan_buf_len(events)!=0;) { 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); free(tmp); } else { diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..9b1a7e8 --- /dev/null +++ b/example/main.go @@ -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() +} diff --git a/tables.go b/tables.go index b505f73..c2e3829 100644 --- a/tables.go +++ b/tables.go @@ -175,6 +175,7 @@ var ( 251: "unlock trackpad (Chrome/Edge)", 255: "toggle touchpad", } + keytoraw = map[string]uint16{ "error": 0, "break": 3, diff --git a/test/main.go b/test/main.go index f62df7c..a0359d5 100644 --- a/test/main.go +++ b/test/main.go @@ -10,6 +10,7 @@ import ( func main() { s := hook.Start() defer hook.End() + tout := time.After(time.Hour * 2) done := false for !done { @@ -19,6 +20,7 @@ func main() { if i.Keychar == 'q' { tout = time.After(0) } + 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) @@ -27,6 +29,7 @@ func main() { } else { fmt.Printf("%+v\n", i) } + case <-tout: fmt.Print("Done.") done = true