Added support for mouse

This commit is contained in:
Deepak Guruswamy 2017-05-27 03:11:46 -07:00
parent 72304ddb9b
commit 4b7fc0a5fb
2 changed files with 29 additions and 3 deletions

View File

@ -99,9 +99,7 @@ func crtTermboxEvt(e termbox.Event) Event {
ne.Path = "/sys/err" ne.Path = "/sys/err"
ne.Data = err ne.Data = err
case termbox.EventMouse: case termbox.EventMouse:
m := EvtMouse{} m := evtMouse(e)
m.X = e.MouseX
m.Y = e.MouseY
ne.Path = "/sys/mouse" ne.Path = "/sys/mouse"
ne.Data = m ne.Data = m
} }
@ -119,6 +117,33 @@ type EvtMouse struct {
Press string Press string
} }
func evtMouse(e termbox.Event) (te EvtMouse) {
te.X = e.MouseX
te.Y = e.MouseY
var m string
switch e.Key {
case termbox.MouseLeft:
m = "MouseLeft"
case termbox.MouseMiddle:
m = "MouseMiddle"
case termbox.MouseRight:
m = "MouseRight"
case termbox.MouseRelease:
m = "MouseRelease"
case termbox.MouseWheelUp:
m = "MouseWheelUp"
case termbox.MouseWheelDown:
m = "MouseWheelDown"
default:
m = "Unknown_Mouse_Button"
}
te.Press = m
return
}
type EvtErr error type EvtErr error
func hookTermboxEvt() { func hookTermboxEvt() {

View File

@ -33,6 +33,7 @@ func Init() error {
if err := tm.Init(); err != nil { if err := tm.Init(); err != nil {
return err return err
} }
tm.SetInputMode(tm.InputEsc | tm.InputMouse)
sysEvtChs = make([]chan Event, 0) sysEvtChs = make([]chan Event, 0)
go hookTermboxEvt() go hookTermboxEvt()