mirror of
https://github.com/robotn/gohook.git
synced 2024-11-25 05:46:52 +08:00
Add lock, Fixed fatal error: concurrent map writes
This commit is contained in:
parent
bbbbefb5ff
commit
bc414970f3
@ -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
|
||||
|
6
hook.go
6
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]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user