gohook/extern.go

41 lines
653 B
Go
Raw Normal View History

package hook
/*
// #include "event/hook_async.h"
*/
import "C"
2019-03-06 03:29:54 +08:00
import (
"log"
"time"
2019-02-19 22:47:03 +08:00
"encoding/json"
)
//export go_send
func go_send(s *C.char) {
str := []byte(C.GoString(s))
out := Event{}
2019-02-19 22:47:03 +08:00
err := json.Unmarshal(str, &out)
if err != nil {
log.Fatal("json.Unmarshal error is: ", err)
}
2019-02-19 22:47:03 +08:00
if out.Keychar != CharUndefined {
lck.Lock()
raw2key[out.Rawcode] = string([]rune{out.Keychar})
lck.Unlock()
}
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
if err != nil {
log.Fatal("json.Unmarshal error is: ", err)
}
2019-02-19 22:47:03 +08:00
// todo: maybe make non-bloking
ev <- out
}