mirror of
https://github.com/robotn/gohook.git
synced 2025-04-28 18:06:42 +08:00
- New event struct mimiking C structs - changed c channel library to eb_chan - changed API to something more palatable
38 lines
516 B
Go
38 lines
516 B
Go
package hook
|
|
|
|
/*
|
|
|
|
|
|
// #include "event/hook_async.h"
|
|
*/
|
|
import "C"
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
//export go_send
|
|
func go_send(s *C.char) {
|
|
str := []byte(C.GoString(s))
|
|
fmt.Println(string(str))
|
|
out := Event{}
|
|
err := json.Unmarshal(str, &out)
|
|
if err != nil{
|
|
log.Fatal(err)
|
|
}
|
|
out.When = time.Now() //at least it's consistent
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
//todo: maybe make non-bloking
|
|
ev <- out
|
|
}
|
|
|
|
////export go_sleep
|
|
//func go_sleep(){
|
|
//
|
|
// time.Sleep(time.Millisecond*50)
|
|
//}
|