mirror of
https://github.com/robotn/gohook.git
synced 2025-05-20 23:44:25 +08:00
Satisfied stringer interface for easier debug and logging, returned old function
what the title says
This commit is contained in:
parent
133a4afc02
commit
9806538d39
53
hook.go
53
hook.go
@ -26,6 +26,7 @@ package hook
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -41,6 +42,7 @@ const (
|
||||
MouseMove = 9
|
||||
MouseDrag = 10
|
||||
MouseWheel = 11
|
||||
FakeEvent = 12
|
||||
//Keychar could be v
|
||||
CharUndefined = 0xFFFF
|
||||
WheelUp = -1
|
||||
@ -68,6 +70,41 @@ type Event struct {
|
||||
Direction uint8 `json:"direction"`
|
||||
}
|
||||
|
||||
var (
|
||||
ev = make(chan Event, 1024)
|
||||
asyncon = false
|
||||
)
|
||||
|
||||
func (e Event) String() string {
|
||||
switch e.Kind {
|
||||
case HookEnabled:
|
||||
return fmt.Sprintf("%v - Event: {Kind: HookEnabled}", e.When)
|
||||
case HookDisabled:
|
||||
return fmt.Sprintf("%v - Event: {Kind: HookDisabled}", e.When)
|
||||
case KeyUp:
|
||||
return fmt.Sprintf("%v - Event: {Kind: KeyUp, Rawcode: %v, Keychar: %v}", e.When, e.Rawcode, e.Keychar)
|
||||
case KeyHold:
|
||||
return fmt.Sprintf("%v - Event: {Kind: KeyHold, Rawcode: %v, Keychar: %v}", e.When, e.Rawcode, e.Keychar)
|
||||
case KeyDown:
|
||||
return fmt.Sprintf("%v - Event: {Kind: KeyDown, Rawcode: %v, Keychar: %v}", e.When, e.Rawcode, e.Keychar)
|
||||
case MouseUp:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseUp, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseHold:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseHold, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseDown:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseDown, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseMove:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseMove, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseDrag:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseDrag, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseWheel:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseWheel, Amount: %v, Rotation: %v, Direction: %v}", e.When, e.Amount, e.Rotation, e.Direction)
|
||||
case FakeEvent:
|
||||
return fmt.Sprintf("%v - Event: {Kind: FakeEvent}",e.When)
|
||||
}
|
||||
return "Unknown event, contact the mantainers"
|
||||
}
|
||||
|
||||
func RawcodetoKeychar(r uint16) string {
|
||||
return raw2key[r]
|
||||
}
|
||||
@ -76,11 +113,6 @@ func KeychartoRawcode(kc string) uint16 {
|
||||
return keytoraw[kc]
|
||||
}
|
||||
|
||||
var (
|
||||
ev = make(chan Event, 1024)
|
||||
asyncon = false
|
||||
)
|
||||
|
||||
// Adds global event hook to OS
|
||||
// returns event channel
|
||||
func Start() chan Event {
|
||||
@ -108,3 +140,14 @@ func End() {
|
||||
}
|
||||
asyncon = false
|
||||
}
|
||||
|
||||
// AddEvent add event listener
|
||||
func AddEvent(key string) int {
|
||||
cs := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(cs))
|
||||
|
||||
eve := C.add_event(cs)
|
||||
geve := int(eve)
|
||||
|
||||
return geve
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user