func Getmouse() *MouseEvent { var mevent C.MEVENT if C.OK != C.getmouse(&mevent) { return nil } return &MouseEvent{ Id: int(mevent.id), X: int(mevent.x), Y: int(mevent.y), Z: int(mevent.z), State: MouseMask(mevent.bstate), } }
/* Gets a mouse event */ func (m *Mouse) GetEvent() bool { if C.getmouse((*C.MEVENT)(m.event)) == 0 { return true } return false }
func (r *FullscreenRenderer) GetChar() Event { c := C.getch() switch c { case C.ERR: // Unexpected error from blocking read r.Close() errorExit("Failed to read /dev/tty") case C.KEY_UP: return Event{Up, 0, nil} case C.KEY_DOWN: return Event{Down, 0, nil} case C.KEY_LEFT: return Event{Left, 0, nil} case C.KEY_RIGHT: return Event{Right, 0, nil} case C.KEY_HOME: return Event{Home, 0, nil} case C.KEY_END: return Event{End, 0, nil} case C.KEY_BACKSPACE: return Event{BSpace, 0, nil} case C.KEY_F0 + 1: return Event{F1, 0, nil} case C.KEY_F0 + 2: return Event{F2, 0, nil} case C.KEY_F0 + 3: return Event{F3, 0, nil} case C.KEY_F0 + 4: return Event{F4, 0, nil} case C.KEY_F0 + 5: return Event{F5, 0, nil} case C.KEY_F0 + 6: return Event{F6, 0, nil} case C.KEY_F0 + 7: return Event{F7, 0, nil} case C.KEY_F0 + 8: return Event{F8, 0, nil} case C.KEY_F0 + 9: return Event{F9, 0, nil} case C.KEY_F0 + 10: return Event{F10, 0, nil} case C.KEY_F0 + 11: return Event{F11, 0, nil} case C.KEY_F0 + 12: return Event{F12, 0, nil} case C.KEY_DC: return Event{Del, 0, nil} case C.KEY_PPAGE: return Event{PgUp, 0, nil} case C.KEY_NPAGE: return Event{PgDn, 0, nil} case C.KEY_BTAB: return Event{BTab, 0, nil} case C.KEY_ENTER: return Event{CtrlM, 0, nil} case C.KEY_SLEFT: return Event{SLeft, 0, nil} case C.KEY_SRIGHT: return Event{SRight, 0, nil} case C.KEY_MOUSE: var me C.MEVENT if C.getmouse(&me) != C.ERR { mod := ((me.bstate & C.BUTTON_SHIFT) | (me.bstate & C.BUTTON_CTRL) | (me.bstate & C.BUTTON_ALT)) > 0 x := int(me.x) y := int(me.y) /* Cannot use BUTTON1_DOUBLE_CLICKED due to mouseinterval(0) */ if (me.bstate & C.BUTTON1_PRESSED) > 0 { now := time.Now() if now.Sub(r.prevDownTime) < doubleClickDuration { r.clickY = append(r.clickY, y) } else { r.clickY = []int{y} r.prevDownTime = now } return Event{Mouse, 0, &MouseEvent{y, x, 0, true, false, mod}} } else if (me.bstate & C.BUTTON1_RELEASED) > 0 { double := false if len(r.clickY) > 1 && r.clickY[0] == r.clickY[1] && time.Now().Sub(r.prevDownTime) < doubleClickDuration { double = true } return Event{Mouse, 0, &MouseEvent{y, x, 0, false, double, mod}} } else if (me.bstate&0x8000000) > 0 || (me.bstate&0x80) > 0 { return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, mod}} } else if (me.bstate & C.BUTTON4_PRESSED) > 0 { return Event{Mouse, 0, &MouseEvent{y, x, 1, false, false, mod}} } } return Event{Invalid, 0, nil} case C.KEY_RESIZE: return Event{Resize, 0, nil} case ESC: return escSequence() case 127: return Event{BSpace, 0, nil} } // CTRL-A ~ CTRL-Z if c >= CtrlA && c <= CtrlZ { return Event{int(c), 0, nil} } // Multi-byte character buffer := []byte{byte(c)} for { r, _ := utf8.DecodeRune(buffer) if r != utf8.RuneError { return Event{Rune, r, nil} } c := C.getch() if c == C.ERR { break } if c >= C.KEY_CODE_YES { C.ungetch(c) break } buffer = append(buffer, byte(c)) } return Event{Invalid, 0, nil} }