diff --git a/extern.go b/extern.go index b1d0aff..4d1df25 100644 --- a/extern.go +++ b/extern.go @@ -24,7 +24,9 @@ func go_send(s *C.char) { } if out.Keychar != CharUndefined { + lck.Lock() raw2key[out.Rawcode] = string([]rune{out.Keychar}) + lck.Unlock() } // todo bury this deep into the C lib so that the time is correct diff --git a/hook.go b/hook.go index 00927b4..ad29a47 100644 --- a/hook.go +++ b/hook.go @@ -26,6 +26,7 @@ import "C" import ( "fmt" + "sync" "time" "unsafe" ) @@ -83,6 +84,8 @@ type Event struct { var ( ev = make(chan Event, 1024) asyncon = false + + lck sync.RWMutex ) // String return hook kind string @@ -136,6 +139,9 @@ func (e Event) String() string { // RawcodetoKeychar rawcode to keychar func RawcodetoKeychar(r uint16) string { + lck.RLock() + defer lck.RUnlock() + return raw2key[r] }