mirror of
https://github.com/robotn/gohook.git
synced 2024-11-14 12:16:39 +08:00
f0ddfd620c
* Part 1 of supporting async events made the dispatch process send events via json through a channel (the c kind), made another function that receives it and sends it trough another channel (the go kind) todo: remove usage of function-local data trough channel todo:find error that is causing the c channel to fill up? * Part 2 of making the lib async - New event struct mimiking C structs - changed c channel library to eb_chan - changed API to something more palatable * General cleanup * updated go.mod oopsie * Probably final touches i swear this time * Changed constants, keychar type and test function now Keychar is a rune, so it can be used as a regular character. * WIP adding better support for conversion between Scancodes and Keychars added table, will add rest of support soon(tm) * finished conversion table * Satisfied stringer interface for easier debug and logging, returned old function what the title says * Satisfied stringer interface for easier debug and logging, returned old function what the title says * forgot to import unsafe
38 lines
787 B
Go
38 lines
787 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/cauefcr/gohook"
|
|
)
|
|
|
|
func main() {
|
|
s := hook.Start()
|
|
defer hook.End()
|
|
tout := time.After(time.Hour*2)
|
|
done := false
|
|
for !done {
|
|
select {
|
|
case i := <-s:
|
|
if i.Kind >= hook.KeyDown && i.Kind <= hook.KeyUp {
|
|
if i.Keychar == 'q' {
|
|
tout = time.After(0)
|
|
}
|
|
fmt.Printf("%v key: %c:%v\n",i.Kind, i.Keychar,i.Rawcode)
|
|
} else if i.Kind >= hook.MouseDown && i.Kind < hook.MouseWheel {
|
|
//fmt.Printf("x: %v, y: %v, button: %v\n", i.X, i.Y, i.Button)
|
|
}else if i.Kind == hook.MouseWheel {
|
|
//fmt.Printf("x: %v, y: %v, button: %v, wheel: %v, rotation: %v\n", i.X, i.Y, i.Button,i.Amount,i.Rotation)
|
|
} else {
|
|
fmt.Printf("%+v\n",i)
|
|
}
|
|
case <-tout:
|
|
fmt.Print("Done.")
|
|
done = true
|
|
break
|
|
}
|
|
}
|
|
|
|
}
|