mirror of
https://github.com/robotn/gohook.git
synced 2024-11-22 11:36:47 +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 {
|
if out.Keychar != CharUndefined {
|
||||||
|
lck.Lock()
|
||||||
raw2key[out.Rawcode] = string([]rune{out.Keychar})
|
raw2key[out.Rawcode] = string([]rune{out.Keychar})
|
||||||
|
lck.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo bury this deep into the C lib so that the time is correct
|
// 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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@ -83,6 +84,8 @@ type Event struct {
|
|||||||
var (
|
var (
|
||||||
ev = make(chan Event, 1024)
|
ev = make(chan Event, 1024)
|
||||||
asyncon = false
|
asyncon = false
|
||||||
|
|
||||||
|
lck sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
// String return hook kind string
|
// String return hook kind string
|
||||||
@ -136,6 +139,9 @@ func (e Event) String() string {
|
|||||||
|
|
||||||
// RawcodetoKeychar rawcode to keychar
|
// RawcodetoKeychar rawcode to keychar
|
||||||
func RawcodetoKeychar(r uint16) string {
|
func RawcodetoKeychar(r uint16) string {
|
||||||
|
lck.RLock()
|
||||||
|
defer lck.RUnlock()
|
||||||
|
|
||||||
return raw2key[r]
|
return raw2key[r]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user