input

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const GamepadLayoutDatSize = layoutDatLen
View Source
const GamepadNumStandardInputs = int(gamepadNumStandardInputs)

Variables

This section is empty.

Functions

func ParseGamepadLayout

func ParseGamepadLayout(data []byte) (GamepadGUID, GamepadLayout, error)

Types

type ButtonInput

type ButtonInput struct {
	Button GamepadStandardInput
	Mode   InputMode
}

type Direction

type Direction uint8
const (
	DirNone  Direction = 0b00000000
	DirUp    Direction = 0b00000001
	DirRight Direction = 0b00000010
	DirDown  Direction = 0b00000100
	DirLeft  Direction = 0b00001000
)

func (Direction) Horz

func (self Direction) Horz() Direction

func (Direction) String

func (self Direction) String() string

func (Direction) Vert

func (self Direction) Vert() Direction

type Gamepad

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

func NewGamepad

func NewGamepad() *Gamepad

func (*Gamepad) Config

func (self *Gamepad) Config() *GamepadConfig

func (*Gamepad) Dir

func (self *Gamepad) Dir() Direction

func (*Gamepad) Dir8

func (self *Gamepad) Dir8() Direction

func (*Gamepad) HorzDir

func (self *Gamepad) HorzDir() Direction

func (*Gamepad) IsIdle

func (self *Gamepad) IsIdle() bool

func (*Gamepad) Pressed

func (self *Gamepad) Pressed(action TriggerAction) bool

func (*Gamepad) PressedTicks

func (self *Gamepad) PressedTicks(action TriggerAction) int32

func (*Gamepad) Repeat

func (self *Gamepad) Repeat(action TriggerAction) bool

func (*Gamepad) RepeatAs

func (self *Gamepad) RepeatAs(action TriggerAction, repeatFirst, repeatNext int32) bool

func (*Gamepad) RepeatDir

func (self *Gamepad) RepeatDir() Direction

func (*Gamepad) RepeatDirAs

func (self *Gamepad) RepeatDirAs(repeatFirst, repeatNext int32) Direction

func (*Gamepad) Status

func (self *Gamepad) Status() GamepadStatus

func (*Gamepad) Trigger

func (self *Gamepad) Trigger(action TriggerAction) bool

func (*Gamepad) TriggerDir

func (self *Gamepad) TriggerDir() Direction

func (*Gamepad) TriggerDir8

func (self *Gamepad) TriggerDir8() Direction

func (*Gamepad) Unwind

func (self *Gamepad) Unwind()

All inputs are blocked (won't be triggered) until a subsequent update determines that actions are not pressed anymore. This is very helpful for scene transitions or context switches where you don't want previous state to affect the new context.

func (*Gamepad) Update

func (self *Gamepad) Update() error

func (*Gamepad) Zero

func (self *Gamepad) Zero()

type GamepadConfig

type GamepadConfig Gamepad

The GamepadConfig allows the user to modify the mappings, triggers, repeat rates and direction buttons for a Gamepad. This object can be obtained through the Gamepad.Config() method.

func (*GamepadConfig) DeleteAllTriggerActions

func (self *GamepadConfig) DeleteAllTriggerActions()

func (*GamepadConfig) DeleteTriggerAction

func (self *GamepadConfig) DeleteTriggerAction(action TriggerAction)

Equivalent to *GamepadConfig.MapTriggerAction(action, nil).

func (*GamepadConfig) GetMapping

func (self *GamepadConfig) GetMapping(action TriggerAction) GamepadTrigger

Returns nil if not mapped.

func (*GamepadConfig) MapTriggerAction

func (self *GamepadConfig) MapTriggerAction(action TriggerAction, trigger GamepadTrigger)

Sets a trigger.

func (*GamepadConfig) MapTriggerActionToButton

func (self *GamepadConfig) MapTriggerActionToButton(action TriggerAction, button GamepadStandardInput)

func (*GamepadConfig) MapTriggerActionToButtons

func (self *GamepadConfig) MapTriggerActionToButtons(action TriggerAction, buttons ...GamepadStandardInput)

func (*GamepadConfig) SetDirButtons

func (self *GamepadConfig) SetDirButtons(dirButtons GamepadDirButtons)

func (*GamepadConfig) SetLayouts

func (self *GamepadConfig) SetLayouts(knownLayouts map[GamepadGUID]GamepadLayout)

func (*GamepadConfig) SetRepeatRate

func (self *GamepadConfig) SetRepeatRate(repeatFirst int32, repeatNext int32)

type GamepadDirButtons

type GamepadDirButtons struct {
	Up    GamepadStandardInput
	Down  GamepadStandardInput
	Right GamepadStandardInput
	Left  GamepadStandardInput
}

Struct for use with *GamepadConfig.SetDirButtons()

func DirButtonsDPad

func DirButtonsDPad() GamepadDirButtons

type GamepadGUID

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

func BytesToGamepadGUID

func BytesToGamepadGUID(buffer []byte) (GamepadGUID, error)

func StringToGamepadGUID

func StringToGamepadGUID(guidStr string) (GamepadGUID, error)

func (GamepadGUID) Equal

func (self GamepadGUID) Equal(other GamepadGUID) bool

func (GamepadGUID) ToBytes

func (self GamepadGUID) ToBytes() []byte

func (GamepadGUID) ToString

func (self GamepadGUID) ToString() string

Uses lowercase for hex values. For uppercase, see ToStringUpper().

func (GamepadGUID) ToStringUpper

func (self GamepadGUID) ToStringUpper() string

func (GamepadGUID) ToZeroName

func (self GamepadGUID) ToZeroName() string

Shorter encoding, uses 0-9, a-z, and then A-Z for compressing sequences of zeroes.

func (GamepadGUID) WriteToBuffer

func (self GamepadGUID) WriteToBuffer(buffer []byte)

type GamepadLayout

func StandardGamepadLayout

func StandardGamepadLayout() GamepadLayout

func (*GamepadLayout) AxisCorrespondence

func (self *GamepadLayout) AxisCorrespondence(index int) (GamepadStandardInput, bool)

Slow.

func (*GamepadLayout) ButtonCorrespondence

func (self *GamepadLayout) ButtonCorrespondence(index int) (GamepadStandardInput, bool)

Slow.

func (*GamepadLayout) Export

func (self *GamepadLayout) Export(writer io.Writer, guid GamepadGUID) error

TODO: could consider adding the gamepad model / type too, but general xbox-like

seems fine, or it could be detected from the layout defined and undefined
inputs.

func (*GamepadLayout) Reset

func (self *GamepadLayout) Reset()

type GamepadLayoutInput

type GamepadLayoutInput uint8

func NewGamepadAnalogButtonLayoutInput

func NewGamepadAnalogButtonLayoutInput(index int) GamepadLayoutInput

func NewGamepadAxisLayoutInput

func NewGamepadAxisLayoutInput(index int) GamepadLayoutInput

func NewGamepadBinaryButtonLayoutInput

func NewGamepadBinaryButtonLayoutInput(index int) GamepadLayoutInput

func (GamepadLayoutInput) Index

func (self GamepadLayoutInput) Index() int

The index will be -1 if undefined.

func (GamepadLayoutInput) IsAnalog

func (self GamepadLayoutInput) IsAnalog() bool

func (GamepadLayoutInput) IsBinary

func (self GamepadLayoutInput) IsBinary() bool

func (GamepadLayoutInput) IsButton

func (self GamepadLayoutInput) IsButton() bool

func (GamepadLayoutInput) Pressed

func (self GamepadLayoutInput) Pressed(id ebiten.GamepadID) bool

func (GamepadLayoutInput) String

func (self GamepadLayoutInput) String() string

func (GamepadLayoutInput) Value

func (self GamepadLayoutInput) Value(id ebiten.GamepadID) float64

type GamepadStandardInput

type GamepadStandardInput uint8
const (
	GamepadUp GamepadStandardInput = iota
	GamepadRight
	GamepadLeft
	GamepadDown

	GamepadButtonTop
	GamepadButtonRight
	GamepadButtonLeft
	GamepadButtonBottom

	GamepadShoulderLeft
	GamepadShoulderRight

	GamepadTriggerLeft
	GamepadTriggerRight

	GamepadLeftStickButton
	GamepadRightStickButton
	GamepadLeftStickHorzAxis
	GamepadLeftStickVertAxis
	GamepadRightStickHorzAxis
	GamepadRightStickVertAxis

	// TODO: maybe use GamepadFuncRight or OptLeft? weird though. it's also "options" on dualshock4
	// also missing dualShock4 touchpad button. could determine by num buttons.
	// also main stick vs secondary stick instead of left and right?
	GamepadStart
	GamepadSelect
	GamepadMeta
)

func (GamepadStandardInput) IsAxis

func (self GamepadStandardInput) IsAxis() bool

func (GamepadStandardInput) StdEquivalent

func (self GamepadStandardInput) StdEquivalent() ebiten.StandardGamepadButton

func (GamepadStandardInput) StdEquivalentPressed

func (self GamepadStandardInput) StdEquivalentPressed(id ebiten.GamepadID) bool

func (GamepadStandardInput) String

func (self GamepadStandardInput) String() string

type GamepadStatus

type GamepadStatus uint8

func (GamepadStatus) IsConfigured

func (self GamepadStatus) IsConfigured() bool

func (GamepadStatus) IsConnected

func (self GamepadStatus) IsConnected() bool

func (GamepadStatus) IsDisconnected

func (self GamepadStatus) IsDisconnected() bool

func (GamepadStatus) IsJustConnected

func (self GamepadStatus) IsJustConnected() bool

func (GamepadStatus) IsJustDisconnected

func (self GamepadStatus) IsJustDisconnected() bool

type GamepadTrigger

type GamepadTrigger interface {
	Pressed(id ebiten.GamepadID, layout *GamepadLayout) bool
	Inputs() []ButtonInput
	String() string
}

type InputMode

type InputMode uint8
const (
	InputModeNormal  InputMode = 0
	InputModeBreaker InputMode = 1 // like a negation
	InputModeOr      InputMode = 2 // one affirmative evaluation is enough

)

type KBGP

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

func NewKBGP

func NewKBGP() *KBGP

func (*KBGP) Dir

func (self *KBGP) Dir() Direction

func (*KBGP) Dir8

func (self *KBGP) Dir8() Direction

func (*KBGP) Gamepad

func (self *KBGP) Gamepad() *Gamepad

func (*KBGP) HorzDir

func (self *KBGP) HorzDir() Direction

func (*KBGP) Keyboard

func (self *KBGP) Keyboard() *Keyboard

func (*KBGP) Pressed

func (self *KBGP) Pressed(action TriggerAction) bool

func (*KBGP) PressedTicks

func (self *KBGP) PressedTicks(action TriggerAction) int32

func (*KBGP) Repeat

func (self *KBGP) Repeat(action TriggerAction) bool

func (*KBGP) RepeatAs

func (self *KBGP) RepeatAs(action TriggerAction, repeatFirst, repeatNext int32) bool

See also repeat detector.

func (*KBGP) RepeatDir

func (self *KBGP) RepeatDir() Direction

func (*KBGP) RepeatDirAs

func (self *KBGP) RepeatDirAs(repeatFirst, repeatNext int32) Direction

See also repeat detector.

func (*KBGP) SetRepeatRate

func (self *KBGP) SetRepeatRate(repeatFirst int32, repeatNext int32)

func (*KBGP) Trigger

func (self *KBGP) Trigger(action TriggerAction) bool

func (*KBGP) TriggerDir

func (self *KBGP) TriggerDir() Direction

func (*KBGP) TriggerDir8

func (self *KBGP) TriggerDir8() Direction

func (*KBGP) Unwind

func (self *KBGP) Unwind()

All inputs are blocked (won't be triggered) until a subsequent update determines that actions are not pressed anymore. This is very helpful for scene transitions or context switches where you don't want previous state to affect the new context.

func (*KBGP) Update

func (self *KBGP) Update() error

func (*KBGP) UsedGamepadMoreRecentlyThanKeyboard

func (self *KBGP) UsedGamepadMoreRecentlyThanKeyboard() bool

func (*KBGP) UsedKeyboardMoreRecentlyThanGamepad

func (self *KBGP) UsedKeyboardMoreRecentlyThanGamepad() bool

func (*KBGP) Zero

func (self *KBGP) Zero()

Sets all inputs to zero. Notice that this can easily cause accidental retriggering (see also Unwind).

type KBGPLike

type KBGPLike interface {
	Update() error

	Zero()
	Unwind()

	Pressed(TriggerAction) bool
	Trigger(TriggerAction) bool
	Repeat(TriggerAction) bool
	RepeatAs(TriggerAction, int32, int32) bool
	PressedTicks(TriggerAction) int32

	Dir() Direction
	TriggerDir() Direction
	Dir8() Direction
	TriggerDir8() Direction
	RepeatDir() Direction
	RepeatDirAs(int32, int32) Direction
}

A common interface implemented by Gamepad, Keyboard and KBGP.

type KeyInput

type KeyInput struct {
	Key  ebiten.Key
	Mode InputMode
}

type KeyList

type KeyList []ebiten.Key

func NewKeyList

func NewKeyList(keys ...ebiten.Key) KeyList

Accepts *any* of the given keys as a trigger.

func (KeyList) Inputs

func (self KeyList) Inputs() []KeyInput

func (KeyList) Pressed

func (self KeyList) Pressed() bool

func (KeyList) String

func (self KeyList) String() string

type Keyboard

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

func NewKeyboard

func NewKeyboard() *Keyboard

func (*Keyboard) Config

func (self *Keyboard) Config() *KeyboardConfig

func (*Keyboard) Dir

func (self *Keyboard) Dir() Direction

func (*Keyboard) Dir8

func (self *Keyboard) Dir8() Direction

func (*Keyboard) HorzDir

func (self *Keyboard) HorzDir() Direction

func (*Keyboard) IsIdle

func (self *Keyboard) IsIdle() bool

func (*Keyboard) Pressed

func (self *Keyboard) Pressed(action TriggerAction) bool

func (*Keyboard) PressedTicks

func (self *Keyboard) PressedTicks(action TriggerAction) int32

func (*Keyboard) Repeat

func (self *Keyboard) Repeat(action TriggerAction) bool

func (*Keyboard) RepeatAs

func (self *Keyboard) RepeatAs(action TriggerAction, repeatFirst, repeatNext int32) bool

func (*Keyboard) RepeatDir

func (self *Keyboard) RepeatDir() Direction

func (*Keyboard) RepeatDirAs

func (self *Keyboard) RepeatDirAs(repeatFirst, repeatNext int32) Direction

func (*Keyboard) Trigger

func (self *Keyboard) Trigger(action TriggerAction) bool

func (*Keyboard) TriggerDir

func (self *Keyboard) TriggerDir() Direction

func (*Keyboard) TriggerDir8

func (self *Keyboard) TriggerDir8() Direction

func (*Keyboard) Unwind

func (self *Keyboard) Unwind()

All inputs are blocked (won't be triggered) until a subsequent update determines that actions are not pressed anymore. This is very helpful for scene transitions or context switches where you don't want previous state to affect the new context.

func (*Keyboard) Update

func (self *Keyboard) Update() error

func (*Keyboard) Zero

func (self *Keyboard) Zero()

type KeyboardConfig

type KeyboardConfig Keyboard

func (*KeyboardConfig) DeleteAllTriggerActions

func (self *KeyboardConfig) DeleteAllTriggerActions()

func (*KeyboardConfig) DeleteTriggerAction

func (self *KeyboardConfig) DeleteTriggerAction(action TriggerAction)

Equivalent to *KeyboardConfig.MapTriggerAction(action, nil).

func (*KeyboardConfig) GetMapping

func (self *KeyboardConfig) GetMapping(action TriggerAction) KeyboardTrigger

Returns nil if not mapped.

func (*KeyboardConfig) MapTriggerAction

func (self *KeyboardConfig) MapTriggerAction(action TriggerAction, trigger KeyboardTrigger)

Sets a trigger.

func (*KeyboardConfig) MapTriggerActionToKey

func (self *KeyboardConfig) MapTriggerActionToKey(action TriggerAction, key ebiten.Key)

func (*KeyboardConfig) MapTriggerActionToKeys

func (self *KeyboardConfig) MapTriggerActionToKeys(action TriggerAction, keys []ebiten.Key)

func (*KeyboardConfig) SetDirTriggers

func (self *KeyboardConfig) SetDirTriggers(dirTriggers KeyboardDirTriggers)

func (*KeyboardConfig) SetRepeatRate

func (self *KeyboardConfig) SetRepeatRate(repeatFirst int32, repeatNext int32)

type KeyboardDirTriggers

type KeyboardDirTriggers struct {
	Up    KeyboardTrigger
	Down  KeyboardTrigger
	Right KeyboardTrigger
	Left  KeyboardTrigger
}

Struct for use with *KeyboardConfig.SetDirTriggers()

func DirKeysArrows

func DirKeysArrows() KeyboardDirTriggers

Get an instance of KeyboardDirTriggers corresponding to directional arrows.

func DirKeysArrowsAndWASD

func DirKeysArrowsAndWASD() KeyboardDirTriggers

Get an instance of KeyboardDirTriggers corresponding to both WASD and directional arrows.

func DirKeysWASD

func DirKeysWASD() KeyboardDirTriggers

Get an instance of KeyboardDirTriggers corresponding to WASD.

type KeyboardTrigger

type KeyboardTrigger interface {
	Pressed() bool
	Inputs() []KeyInput
	String() string
}

type MultiButton

type MultiButton struct {
	ButtonInputs []ButtonInput
}

func NewMultiButton

func NewMultiButton(buttons ...GamepadStandardInput) MultiButton

func (*MultiButton) Add

func (self *MultiButton) Add(button GamepadStandardInput)

func (*MultiButton) AddBreaker

func (self *MultiButton) AddBreaker(button GamepadStandardInput)

func (MultiButton) Inputs

func (self MultiButton) Inputs() []ButtonInput

func (MultiButton) Pressed

func (self MultiButton) Pressed(id ebiten.GamepadID, layout *GamepadLayout) bool

func (MultiButton) String

func (self MultiButton) String() string

type MultiKey

type MultiKey struct {
	KeyInputs []KeyInput
}

func NewMultiKey

func NewMultiKey(keys ...ebiten.Key) MultiKey

func (*MultiKey) AddBreakerKey

func (self *MultiKey) AddBreakerKey(key ebiten.Key)

func (*MultiKey) AddNormalKey

func (self *MultiKey) AddNormalKey(key ebiten.Key)

func (MultiKey) Inputs

func (self MultiKey) Inputs() []KeyInput

func (MultiKey) Pressed

func (self MultiKey) Pressed() bool

func (MultiKey) String

func (self MultiKey) String() string

type RepeatDetectorKBGP

type RepeatDetectorKBGP struct {
	First int32
	Next  int32
}

NOTE: I don't think generics are relevant for this right now.

func (RepeatDetectorKBGP) Repeat

func (self RepeatDetectorKBGP) Repeat(input *KBGP, action TriggerAction) bool

func (RepeatDetectorKBGP) RepeatDir

func (self RepeatDetectorKBGP) RepeatDir(input *KBGP) Direction

type SingleButton

type SingleButton GamepadStandardInput

func (SingleButton) Inputs

func (self SingleButton) Inputs() []ButtonInput

func (SingleButton) Pressed

func (self SingleButton) Pressed(id ebiten.GamepadID, layout *GamepadLayout) bool

func (SingleButton) String

func (self SingleButton) String() string

type SingleKey

type SingleKey ebiten.Key

func (SingleKey) Inputs

func (self SingleKey) Inputs() []KeyInput

func (SingleKey) Pressed

func (self SingleKey) Pressed() bool

func (SingleKey) String

func (self SingleKey) String() string

type TriggerAction

type TriggerAction uint16

type UnassignedButton

type UnassignedButton struct{}

func (UnassignedButton) Inputs

func (self UnassignedButton) Inputs() []ButtonInput

func (UnassignedButton) Pressed

func (self UnassignedButton) Pressed(id ebiten.GamepadID, layout *GamepadLayout) bool

func (UnassignedButton) String

func (self UnassignedButton) String() string

type UnassignedKey

type UnassignedKey struct{}

func (UnassignedKey) Inputs

func (self UnassignedKey) Inputs() []KeyInput

func (UnassignedKey) Pressed

func (self UnassignedKey) Pressed() bool

func (UnassignedKey) String

func (self UnassignedKey) String() string

Jump to

Keyboard shortcuts

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