input

package
v0.0.0-...-20810c9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeySpace        string = "space"
	KeyApostrophe   string = "apostrophe"
	KeyComma        string = "comma"
	KeyMinus        string = "minus"
	KeyPeriod       string = "period"
	KeySlash        string = "slash"
	Key0            string = "0"
	Key1            string = "1"
	Key2            string = "2"
	Key3            string = "3"
	Key4            string = "4"
	Key5            string = "5"
	Key6            string = "6"
	Key7            string = "7"
	Key8            string = "8"
	Key9            string = "9"
	KeySemicolon    string = "semicolon"
	KeyEqual        string = "equal"
	KeyA            string = "a"
	KeyB            string = "b"
	KeyC            string = "c"
	KeyD            string = "d"
	KeyE            string = "e"
	KeyF            string = "f"
	KeyG            string = "g"
	KeyH            string = "h"
	KeyI            string = "i"
	KeyJ            string = "j"
	KeyK            string = "k"
	KeyL            string = "l"
	KeyM            string = "m"
	KeyN            string = "n"
	KeyO            string = "o"
	KeyP            string = "p"
	KeyQ            string = "q"
	KeyR            string = "r"
	KeyS            string = "s"
	KeyT            string = "t"
	KeyU            string = "u"
	KeyV            string = "v"
	KeyW            string = "w"
	KeyX            string = "x"
	KeyY            string = "y"
	KeyZ            string = "z"
	KeyLeftBracket  string = "["
	KeyBackslash    string = "/"
	KeyRightBracket string = "]"
	KeyGraveAccent  string = "`"
	KeyWorld1       string = "world1"
	KeyWorld2       string = "world2"
	KeyEscape       string = "escape"
	KeyEnter        string = "enter"
	KeyTab          string = "tab"
	KeyBackspace    string = "backspace"
	KeyInsert       string = "insert"
	KeyDelete       string = "delete"
	KeyRight        string = "right"
	KeyLeft         string = "left"
	KeyDown         string = "down"
	KeyUp           string = "up"
	KeyPageUp       string = "page up"
	KeyPageDown     string = "page down"
	KeyHome         string = "home"
	KeyEnd          string = "end"
	KeyCapsLock     string = "caps lock"
	KeyScrollLock   string = "scroll lock"
	KeyNumLock      string = "num lock"
	KeyPrintScreen  string = "print"
	KeyPause        string = "pause"
	KeyF1           string = "f1"
	KeyF2           string = "f2"
	KeyF3           string = "f3"
	KeyF4           string = "f4"
	KeyF5           string = "f5"
	KeyF6           string = "f6"
	KeyF7           string = "f7"
	KeyF8           string = "f8"
	KeyF9           string = "f9"
	KeyF10          string = "f10"
	KeyF11          string = "f11"
	KeyF12          string = "f12"
	KeyF13          string = "f13"
	KeyF14          string = "f14"
	KeyF15          string = "f15"
	KeyF16          string = "f16"
	KeyF17          string = "f17"
	KeyF18          string = "f18"
	KeyF19          string = "f19"
	KeyF20          string = "f20"
	KeyF21          string = "f21"
	KeyF22          string = "f22"
	KeyF23          string = "f23"
	KeyF24          string = "f24"
	KeyF25          string = "f25"
	KeyKP0          string = "numpad 0"
	KeyKP1          string = "numpad 1"
	KeyKP2          string = "numpad 2"
	KeyKP3          string = "numpad 3"
	KeyKP4          string = "numpad 4"
	KeyKP5          string = "numpad 5"
	KeyKP6          string = "numpad 6"
	KeyKP7          string = "numpad 7"
	KeyKP8          string = "numpad 8"
	KeyKP9          string = "numpad 9"
	KeyKPDecimal    string = "numpad decimal"
	KeyKPDivide     string = "numpad divide"
	KeyKPMultiply   string = "numpad multiply"
	KeyKPSubtract   string = "numpad subtract"
	KeyKPAdd        string = "numpad add"
	KeyKPEnter      string = "numpad enter"
	KeyKPEqual      string = "numpad equal"
	KeyLeftShift    string = "left shift"
	KeyLeftControl  string = "left ctrl"
	KeyLeftAlt      string = "left alt"
	KeyLeftSuper    string = "left super"
	KeyRightShift   string = "right shift"
	KeyRightControl string = "right control"
	KeyRightAlt     string = "right alt"
	KeyRightSuper   string = "right super"
	KeyMenu         string = "menu"
)

Variables

View Source
var KeyInfos = map[string]KeyInfo{
	KeySpace:        {Upper: ' ', Lower: ' '},
	KeyApostrophe:   {Upper: '"', Lower: '\''},
	KeyComma:        {Upper: '<', Lower: ','},
	KeyMinus:        {Upper: '_', Lower: '-'},
	KeyPeriod:       {Upper: '>', Lower: '.'},
	KeySlash:        {Upper: '?', Lower: '/'},
	Key0:            {Upper: ')', Lower: '0'},
	Key1:            {Upper: '!', Lower: '1'},
	Key2:            {Upper: '@', Lower: '2'},
	Key3:            {Upper: '#', Lower: '3'},
	Key4:            {Upper: '$', Lower: '4'},
	Key5:            {Upper: '%', Lower: '5'},
	Key6:            {Upper: '^', Lower: '6'},
	Key7:            {Upper: '&', Lower: '7'},
	Key8:            {Upper: '*', Lower: '8'},
	Key9:            {Upper: '(', Lower: '9'},
	KeySemicolon:    {Upper: ':', Lower: ';'},
	KeyEqual:        {Upper: '+', Lower: '='},
	KeyA:            {Upper: 'A', Lower: 'a'},
	KeyB:            {Upper: 'B', Lower: 'b'},
	KeyC:            {Upper: 'C', Lower: 'c'},
	KeyD:            {Upper: 'D', Lower: 'd'},
	KeyE:            {Upper: 'E', Lower: 'e'},
	KeyF:            {Upper: 'F', Lower: 'f'},
	KeyG:            {Upper: 'G', Lower: 'g'},
	KeyH:            {Upper: 'H', Lower: 'h'},
	KeyI:            {Upper: 'I', Lower: 'i'},
	KeyJ:            {Upper: 'J', Lower: 'j'},
	KeyK:            {Upper: 'K', Lower: 'k'},
	KeyL:            {Upper: 'L', Lower: 'l'},
	KeyM:            {Upper: 'M', Lower: 'm'},
	KeyN:            {Upper: 'N', Lower: 'n'},
	KeyO:            {Upper: 'O', Lower: 'o'},
	KeyP:            {Upper: 'P', Lower: 'p'},
	KeyQ:            {Upper: 'Q', Lower: 'q'},
	KeyR:            {Upper: 'R', Lower: 'r'},
	KeyS:            {Upper: 'S', Lower: 's'},
	KeyT:            {Upper: 'T', Lower: 't'},
	KeyU:            {Upper: 'U', Lower: 'u'},
	KeyV:            {Upper: 'V', Lower: 'v'},
	KeyW:            {Upper: 'W', Lower: 'w'},
	KeyX:            {Upper: 'X', Lower: 'x'},
	KeyY:            {Upper: 'Y', Lower: 'y'},
	KeyZ:            {Upper: 'Z', Lower: 'z'},
	KeyLeftBracket:  {Upper: '{', Lower: '['},
	KeyBackslash:    {Upper: '|', Lower: '\\'},
	KeyRightBracket: {Upper: '}', Lower: ']'},
	KeyGraveAccent:  {Upper: '~', Lower: '`'},
	KeyEnter:        {Upper: '\n', Lower: '\n'},
	KeyTab:          {Upper: '\t', Lower: '\t'},
	KeyBackspace:    {Upper: '\b', Lower: '\b'},
	KeyKP0:          {Upper: '0', Lower: '0'},
	KeyKP1:          {Upper: '1', Lower: '1'},
	KeyKP2:          {Upper: '2', Lower: '2'},
	KeyKP3:          {Upper: '3', Lower: '3'},
	KeyKP4:          {Upper: '4', Lower: '4'},
	KeyKP5:          {Upper: '5', Lower: '5'},
	KeyKP6:          {Upper: '6', Lower: '6'},
	KeyKP7:          {Upper: '7', Lower: '7'},
	KeyKP8:          {Upper: '8', Lower: '8'},
	KeyKP9:          {Upper: '9', Lower: '9'},
	KeyKPDecimal:    {Upper: '.', Lower: '.'},
	KeyKPDivide:     {Upper: '/', Lower: '/'},
	KeyKPMultiply:   {Upper: '*', Lower: '*'},
	KeyKPSubtract:   {Upper: '-', Lower: '-'},
	KeyKPAdd:        {Upper: '+', Lower: '+'},
	KeyKPEnter:      {Upper: '\n', Lower: '\n'},
	KeyKPEqual:      {Upper: '=', Lower: '='},
}

Functions

This section is empty.

Types

type Action

type Action struct {
	Name             string
	Enabled          react.Value[bool]
	Trigger          Trigger
	Data             Data
	Triggered        bool
	OverridePriority int
}

func NewAction

func NewAction(name string, trigger Trigger) *Action

func (*Action) Init

func (action *Action) Init(inputs InputSystem)

func (Action) Priority

func (action Action) Priority() int

func (*Action) String

func (action *Action) String() string

func (*Action) Update

func (action *Action) Update(inputs InputSystem)

type ActionHandler

type ActionHandler func(action *Action)

type ActionSet

type ActionSet struct {
	Name      string
	Enabled   react.Value[bool]
	Actions   Actions
	Triggered ds.CircularQueue[*Action]
}

func CreateActionSet

func CreateActionSet(name string, actions map[string]Trigger) *ActionSet

func NewActionSet

func NewActionSet(name string) *ActionSet

func (*ActionSet) Add

func (set *ActionSet) Add(action *Action)

func (*ActionSet) Init

func (set *ActionSet) Init(inputs InputSystem)

func (*ActionSet) Iterator

func (set *ActionSet) Iterator() ds.Iterator[*Action]

func (*ActionSet) Update

func (set *ActionSet) Update(inputs InputSystem)

type ActionSets

type ActionSets struct {
	Sets    map[string]*ActionSet
	Handler ActionHandler
}

func CreateActionSets

func CreateActionSets(actionSets ActionSetsInput) ActionSets

func NewActionSets

func NewActionSets() ActionSets

func (*ActionSets) Add

func (sets *ActionSets) Add(set *ActionSet)

func (*ActionSets) Init

func (sets *ActionSets) Init(inputs InputSystem)

func (*ActionSets) Iterable

func (sets *ActionSets) Iterable() ds.Iterable[*Action]

func (*ActionSets) Update

func (sets *ActionSets) Update(inputs InputSystem)

type ActionSetsInput

type ActionSetsInput = map[string]map[string]Trigger

type Actions

type Actions []*Action

func (Actions) Len

func (actions Actions) Len() int

func (Actions) Less

func (actions Actions) Less(i, j int) bool

func (Actions) Sort

func (actions Actions) Sort()

func (Actions) Swap

func (actions Actions) Swap(i, j int)

type Data

type Data struct {
	Value  float32
	Inputs []*Input
}

func (*Data) AddInputs

func (data *Data) AddInputs(inputs []*Input)

func (*Data) SetInputs

func (data *Data) SetInputs(inputs []*Input)

type Device

type Device struct {
	Name      string
	Type      DeviceType
	Inputs    []*Input
	Connected react.Value[bool]
}

func NewDevice

func NewDevice(name string, deviceType DeviceType) *Device

func (*Device) Add

func (device *Device) Add(name string) *Input

type DeviceType

type DeviceType string
const (
	DeviceTypeKeyboard   DeviceType = "keyboard"
	DeviceTypeMouse      DeviceType = "mouse"
	DeviceTypeController DeviceType = "controller"
	DeviceTypeTouch      DeviceType = "touch"
)

type EmptySystem

type EmptySystem struct{}

func (*EmptySystem) Devices

func (in *EmptySystem) Devices() []*Device

func (*EmptySystem) Events

func (in *EmptySystem) Events() *core.Listeners[SystemEvents]

func (*EmptySystem) Get

func (in *EmptySystem) Get(name string) *Input

func (*EmptySystem) InputTime

func (in *EmptySystem) InputTime() time.Time

func (*EmptySystem) Inputs

func (in *EmptySystem) Inputs() []*Input

func (*EmptySystem) Points

func (in *EmptySystem) Points() []*Point

type Gesture

type Gesture struct {
	Inputs  []*Input
	MinTime time.Duration
	Ignore  []*Input
}

type Input

type Input struct {
	Name             string
	Value            float32
	ValueChanged     time.Time
	ValueDuration    time.Duration
	PreviousValue    float32
	PreviousChanged  time.Time
	PreviousDuration time.Duration
	Device           *Device
	Action           *Action
}

func New

func New(name string) *Input

func (*Input) Cancel

func (i *Input) Cancel()

func (*Input) HasCancel

func (i *Input) HasCancel() bool

func (*Input) Set

func (i *Input) Set(value float32, now time.Time) bool

func (*Input) UpdateDuration

func (i *Input) UpdateDuration(now time.Time)

type InputSystem

type InputSystem interface {
	Devices() []*Device
	Inputs() []*Input
	Points() []*Point
	Events() *core.Listeners[SystemEvents]
	Get(inputName string) *Input
	InputTime() time.Time
}

type KeyInfo

type KeyInfo struct {
	Lower rune
	Upper rune
}

type KeyTrigger

type KeyTrigger struct {
	Key             string
	Keys            []string
	Shift           bool
	Ctrl            bool
	Alt             bool
	CmdCtrl         bool
	Cmd             bool
	PressInterval   time.Duration
	FirstPressDelay time.Duration
	Up              bool
	UpOnly          bool
	Down            bool
}

type Point

type Point struct {
	X     float32
	Y     float32
	Index int
}

type System

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

func NewSystem

func NewSystem() *System

func (*System) AddPoint

func (sys *System) AddPoint(point *Point)

func (*System) ConnectDevice

func (in *System) ConnectDevice(newDevice *Device)

func (*System) ConnectInput

func (in *System) ConnectInput(newInput *Input)

func (*System) Devices

func (sys *System) Devices() []*Device

func (*System) DisconnectDevice

func (in *System) DisconnectDevice(oldDevice *Device)

func (*System) DisconnectInput

func (in *System) DisconnectInput(oldInput *Input)

func (*System) Events

func (sys *System) Events() *core.Listeners[SystemEvents]

func (*System) Get

func (sys *System) Get(inputName string) *Input

func (*System) InputTime

func (sys *System) InputTime() time.Time

func (*System) Inputs

func (sys *System) Inputs() []*Input

func (*System) Points

func (sys *System) Points() []*Point

func (*System) SetInputEnter

func (in *System) SetInputEnter(ia *Point)

func (*System) SetInputLeave

func (in *System) SetInputLeave(ia *Point)

func (*System) SetInputPoint

func (in *System) SetInputPoint(ia *Point, x, y float32)

func (*System) SetInputTime

func (sys *System) SetInputTime(now time.Time)

func (*System) SetInputValue

func (in *System) SetInputValue(ia *Input, newValue float32)

type SystemEvents

type SystemEvents struct {
	DeviceConnected    func(newDevice Device)
	DeviceDisconnected func(oldDevice Device)
	InputConnected     func(newInput Input)
	InputDisconnected  func(oldInput Input)
	InputChange        func(input Input)
	PointConnected     func(newPoint Point)
	PointDisconnected  func(oldPoint Point)
	PointChange        func(point Point)
	PointLeave         func(point Point)
	PointEnter         func(point Point)
	InputChangeMap     map[string]func(input Input)
}

type Trigger

type Trigger interface {
	Init(inputs InputSystem)
	Update(inputs InputSystem) (Data, bool)
	InputCount() int
}

func NewKeyTrigger

func NewKeyTrigger(trigger KeyTrigger) Trigger

type TriggerBuilder

type TriggerBuilder struct{}

func (*TriggerBuilder) And

func (builder *TriggerBuilder) And(triggers ...Trigger) Trigger

func (*TriggerBuilder) FirstInterval

func (builder *TriggerBuilder) FirstInterval(firstInterval time.Duration, interval time.Duration, trigger Trigger) Trigger

func (*TriggerBuilder) Interval

func (builder *TriggerBuilder) Interval(interval time.Duration, trigger Trigger) Trigger

func (*TriggerBuilder) Key

func (builder *TriggerBuilder) Key(key KeyTrigger) Trigger

func (*TriggerBuilder) Named

func (builder *TriggerBuilder) Named(name string) Trigger

func (*TriggerBuilder) Off

func (builder *TriggerBuilder) Off(name string) Trigger

func (*TriggerBuilder) On

func (builder *TriggerBuilder) On(name string) Trigger

func (*TriggerBuilder) Once

func (builder *TriggerBuilder) Once(trigger Trigger) Trigger

func (*TriggerBuilder) Or

func (builder *TriggerBuilder) Or(triggers ...Trigger) Trigger

func (*TriggerBuilder) Value

func (builder *TriggerBuilder) Value(value float32, trigger Trigger) Trigger

type TriggerGroup

type TriggerGroup struct {
	Op       TriggerGroupOp
	All      bool
	Triggers []Trigger
}

func (*TriggerGroup) Init

func (i *TriggerGroup) Init(inputs InputSystem)

func (*TriggerGroup) InputCount

func (i *TriggerGroup) InputCount() int

func (*TriggerGroup) Update

func (i *TriggerGroup) Update(inputs InputSystem) (Data, bool)

type TriggerGroupOp

type TriggerGroupOp string
const (
	TriggerGroupOpMin     TriggerGroupOp = "min"
	TriggerGroupOpMax     TriggerGroupOp = "max"
	TriggerGroupOpAverage TriggerGroupOp = "mavg"
)

type TriggerInterval

type TriggerInterval struct {
	Trigger       Trigger
	FirstInterval time.Duration
	Interval      time.Duration
	Strict        bool
	// contains filtered or unexported fields
}

func (*TriggerInterval) Init

func (i *TriggerInterval) Init(inputs InputSystem)

func (*TriggerInterval) InputCount

func (i *TriggerInterval) InputCount() int

func (*TriggerInterval) Update

func (i *TriggerInterval) Update(inputs InputSystem) (Data, bool)

type TriggerNamed

type TriggerNamed struct {
	Name string
	// contains filtered or unexported fields
}

func (*TriggerNamed) Init

func (i *TriggerNamed) Init(inputs InputSystem)

func (*TriggerNamed) InputCount

func (i *TriggerNamed) InputCount() int

func (*TriggerNamed) Update

func (i *TriggerNamed) Update(inputs InputSystem) (Data, bool)

type TriggerNone

type TriggerNone struct{}

func (*TriggerNone) Init

func (i *TriggerNone) Init(inputs InputSystem)

func (*TriggerNone) InputCount

func (i *TriggerNone) InputCount() int

func (*TriggerNone) Update

func (i *TriggerNone) Update(inputs InputSystem) (Data, bool)

type TriggerOnce

type TriggerOnce struct {
	Trigger Trigger
	// contains filtered or unexported fields
}

func (*TriggerOnce) Init

func (i *TriggerOnce) Init(inputs InputSystem)

func (*TriggerOnce) InputCount

func (i *TriggerOnce) InputCount() int

func (*TriggerOnce) Update

func (i *TriggerOnce) Update(inputs InputSystem) (Data, bool)

type TriggerRange

type TriggerRange struct {
	TriggerMin        float32
	TriggerMinInclude bool
	TriggerMax        float32
	TriggerMaxInclude bool
	Trigger           Trigger
}

func (*TriggerRange) Init

func (i *TriggerRange) Init(inputs InputSystem)

func (*TriggerRange) InputCount

func (i *TriggerRange) InputCount() int

func (*TriggerRange) Update

func (i *TriggerRange) Update(inputs InputSystem) (Data, bool)

type TriggerValue

type TriggerValue struct {
	Value   float32
	Epsilon float32
	Trigger Trigger
}

func (*TriggerValue) Init

func (i *TriggerValue) Init(inputs InputSystem)

func (*TriggerValue) InputCount

func (i *TriggerValue) InputCount() int

func (*TriggerValue) Update

func (i *TriggerValue) Update(inputs InputSystem) (Data, bool)

type Vector

type Vector struct {
	X *Input
	Y *Input
}

Jump to

Keyboard shortcuts

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