2019-02-19 22:31:25 +08:00
|
|
|
package hook
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
// #include "event/hook_async.h"
|
|
|
|
*/
|
|
|
|
import "C"
|
2019-03-06 03:29:54 +08:00
|
|
|
|
2019-02-19 22:31:25 +08:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
2019-02-19 22:47:03 +08:00
|
|
|
|
|
|
|
"encoding/json"
|
2019-02-19 22:31:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
//export go_send
|
|
|
|
func go_send(s *C.char) {
|
|
|
|
str := []byte(C.GoString(s))
|
|
|
|
out := Event{}
|
2019-02-19 22:47:03 +08:00
|
|
|
|
2019-02-19 22:31:25 +08:00
|
|
|
err := json.Unmarshal(str, &out)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-02-19 22:47:03 +08:00
|
|
|
|
2019-02-19 22:31:25 +08:00
|
|
|
if out.Keychar != CharUndefined {
|
2019-03-16 01:45:47 +08:00
|
|
|
lck.Lock()
|
2019-02-19 22:31:25 +08:00
|
|
|
raw2key[out.Rawcode] = string([]rune{out.Keychar})
|
2019-03-16 01:45:47 +08:00
|
|
|
lck.Unlock()
|
2019-02-19 22:31:25 +08:00
|
|
|
}
|
2019-02-19 22:47:03 +08:00
|
|
|
|
|
|
|
// todo bury this deep into the C lib so that the time is correct
|
|
|
|
out.When = time.Now() // at least it's consistent
|
2019-02-19 22:31:25 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-02-19 22:47:03 +08:00
|
|
|
|
|
|
|
// todo: maybe make non-bloking
|
2019-02-19 22:31:25 +08:00
|
|
|
ev <- out
|
|
|
|
}
|