mouse

package
Version: v0.0.0-...-793ea6c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2021 License: BSD-3-Clause Imports: 4 Imported by: 7

Documentation

Overview

Package mouse implements various mouse related data types.

Index

Constants

View Source
const (
	Left   = One
	Right  = Two
	Wheel  = Three
	Middle = Three
)

Left, Right, Middle and Wheel are simply aliases. Their true names are mouse button One, Two, and Three (for both Middle and Wheel, respectively).

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button uint8

Button represents a single mouse button.

const (
	Invalid Button = iota
	One
	Two
	Three
	Four
	Five
	Six
	Seven
	Eight
)

Mouse button constants for buttons one through eight. The Invalid button is declared to help users detect uninitialized variables.

func (Button) String

func (i Button) String() string

type ButtonEvent

type ButtonEvent struct {
	T      time.Time
	Button Button
	State  State
}

ButtonEvent represents an single mouse button event.

func (ButtonEvent) String

func (b ButtonEvent) String() string

String returns an string representation of this event.

func (ButtonEvent) Time

func (b ButtonEvent) Time() time.Time

Time returns the time at which this event occured.

type Scrolled

type Scrolled struct {
	T time.Time

	// Amount of scrolling in horizontal (X) and vertical (Y) directions.
	X, Y float64
}

Scrolled is an event where the user has scrolled their mouse wheel.

func (Scrolled) String

func (s Scrolled) String() string

String returns a string representation of this event.

func (Scrolled) Time

func (s Scrolled) Time() time.Time

Time implements the Event interface.

type State

type State uint8

State represents a single mouse state, such as Up or Down.

const (
	InvalidState State = iota
	Down
	Up
)

Mouse button state constants, Down implies the button is currently pressed down, and up implies it is not. The InvalidState is declared to help users detect uninitialized variables.

func (State) String

func (i State) String() string

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher watches the state of various mouse buttons and their states.

func NewWatcher

func NewWatcher() *Watcher

NewWatcher returns a new, initialized, mouse watcher.

func (*Watcher) Down

func (w *Watcher) Down(button Button) bool

Down tells whether the specified mouse button is currently in the down state.

func (*Watcher) EachState

func (w *Watcher) EachState(f func(b Button, s State) bool)

EachState calls f with each known button to this watcher and it's current button state. It does so until the function returns false or there are no more buttons known to the watcher.

func (*Watcher) SetState

func (w *Watcher) SetState(button Button, state State)

SetState specifies the current state of the specified mouse button.

func (*Watcher) State

func (w *Watcher) State(button Button) State

State returns the current state of the specified mouse button.

func (*Watcher) States

func (w *Watcher) States() []State

States returns an copy of the internal mouse button state lookup table used by this watcher. The indices of the lookup table are literally Button values:

states := watcher.States()
leftState := states[mouse.Left]
if leftState != InvalidState {
    fmt.Println("The left mouse button state is", leftState)
}

States for buttons not known to the watcher are equal to InvalidState.

At max the lookup table will be of length 256 (as Button is declared as a uint8), but it may be less.

func (*Watcher) String

func (w *Watcher) String() string

String returns a multi-line string representation of this mouse watcher and it's associated states.

func (*Watcher) Up

func (w *Watcher) Up(button Button) bool

Up tells whether the specified mouse button is currently in the up state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL