diff --git a/appveyor.yml b/appveyor.yml index 4f9c648..e107716 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.17.5 + GOVERSION: 1.17.6 # GOPATH: c:\gopath # scripts that run after cloning repository diff --git a/event/os.h b/event/os.h index 60a4d86..25bd8d7 100644 --- a/event/os.h +++ b/event/os.h @@ -5,8 +5,7 @@ /* Python versions under 2.5 don't support this macro, but it's not * terribly difficult to replicate: */ #ifndef PyModule_AddIntMacro - #define PyModule_AddIntMacro(module, macro) \ - PyModule_AddIntConstant(module, #macro, macro) + #define PyModule_AddIntMacro(module, macro) PyModule_AddIntConstant(module, #macro, macro) #endif /* PyModule_AddIntMacro */ #if !defined(IS_MACOSX) && defined(__APPLE__) && defined(__MACH__) diff --git a/event/pub.h b/event/pub.h index 80a76d9..fc87386 100644 --- a/event/pub.h +++ b/event/pub.h @@ -73,10 +73,8 @@ struct _MEvent { typedef struct _MEvent MEvent; // typedef MMBitmap *MMBitmapRef; - MEvent mEvent; - bool loggerProc(unsigned int level, const char *format, ...) { bool status = false; diff --git a/examples/event/main.go b/examples/event/main.go new file mode 100644 index 0000000..404aec0 --- /dev/null +++ b/examples/event/main.go @@ -0,0 +1,113 @@ +// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// https://github.com/go-vgo/robotgo/blob/master/LICENSE +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +package main + +import ( + "fmt" + + hook "github.com/robotn/gohook" +) + +func addEvent() { + fmt.Println("--- Please press ctrl + shift + q ---") + ok := hook.AddEvents("q", "ctrl", "shift") + if ok { + fmt.Println("add events...") + } + + fmt.Println("--- Please press w---") + ok = hook.AddEvents("w") + if ok { + fmt.Println("add events") + } + + // start hook + s := hook.Start() + // end hook + defer hook.End() + + for ev := range s { + fmt.Println("hook: ", ev) + } +} + +func addMouse() { + fmt.Println("--- Please press left mouse button ---") + ok := hook.AddMouse("left") + if ok { + fmt.Println("add mouse...") + } + + fmt.Println("--- Please press left mouse button and move mosue to 100,100 ---") + ok = hook.AddMouse("left", 100, 100) + if ok { + fmt.Println("add mouse and move to 100,100 ...") + } + + fmt.Println("--- Please move mosue to 100,100 ---") + ok = hook.AddMousePos(100, 100) + if ok { + fmt.Println(" move mouse to 100,100 ...") + } +} + +func add() { + fmt.Println("--- Please press v---") + eve := hook.AddEvent("v") + + if eve { + fmt.Println("--- You press v---", "v") + } + + fmt.Println("--- Please press k---") + keve := hook.AddEvent("k") + if keve { + fmt.Println("--- You press k---", "k") + } + + fmt.Println("--- Please press f1---") + feve := hook.AddEvent("f1") + if feve { + fmt.Println("You press...", "f1") + } +} + +func event() { + //////////////////////////////////////////////////////////////////////////////// + // Global event listener + //////////////////////////////////////////////////////////////////////////////// + + add() + + fmt.Println("--- Please press left mouse button---") + mleft := hook.AddEvent("mleft") + if mleft { + fmt.Println("--- You press left mouse button---", "mleft") + } + + mright := hook.AddEvent("mright") + if mright { + fmt.Println("--- You press right mouse button---", "mright") + } + + // stop AddEvent + // hook.StopEvent() +} + +func main() { + fmt.Println("test begin...") + + addEvent() + + addMouse() + + event() +} diff --git a/examples/main.go b/examples/main.go index bbe68f7..2a1ab8b 100644 --- a/examples/main.go +++ b/examples/main.go @@ -22,6 +22,20 @@ func registerEvent() { <-hook.Process(s) } +func addMouse() { + fmt.Println("--- Please press left mouse button to see it's position and the right mouse button to exit ---") + hook.Register(hook.MouseDown, []string{}, func(e hook.Event) { + if e.Button == hook.MouseMap["left"] { + fmt.Printf("mouse left @ %v - %v\n", e.X, e.Y) + } else if e.Button == hook.MouseMap["right"] { + hook.End() + } + }) + + s := hook.Start() + <-hook.Process(s) +} + // hook listen and return values using detailed examples func add() { fmt.Println("hook add...") @@ -50,6 +64,9 @@ func base() { for ev := range evChan { fmt.Println("hook: ", ev) + if ev.Keychar == 'q' { + break + } } } @@ -59,4 +76,5 @@ func main() { base() add() + addMouse() }