Documentation ¶
Overview ¶
Package gamepad implements access to the system's gamepad or joystick API.
This package currently supports windows, linux, android, and js/wasm.
Index ¶
- func Update() error
- type Axis
- type Button
- type Gamepad
- func (g *Gamepad) Axis(index int) float32
- func (g *Gamepad) AxisToIndex(axis Axis) int
- func (g *Gamepad) Button(index int) (float32, bool)
- func (g *Gamepad) ButtonToIndex(btn Button) int
- func (g *Gamepad) IndexToAxis(index int) Axis
- func (g *Gamepad) IndexToButton(index int) Button
- func (g *Gamepad) Name() string
- func (g *Gamepad) NumAxis() int
- func (g *Gamepad) NumButton() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Axis ¶ added in v0.0.4
type Axis int
Axis is an analog directional input from -1 to +1. Some AxisUnknown axes may be from 0 to +1 instead.
const ( // AxisUnknown is any axis not listed in this enumeration, or any // axis on a gamepad that does not have a known layout. AxisUnknown Axis = iota - 1 // AxisLeftX is the left-right tilt of the left stick, with -1 as full // left and +1 as full right. AxisLeftX // AxisLeftY is the up-down tilt of the left stick, with -1 as full // up and +1 as full down. AxisLeftY // AxisRightX is the left-right tilt of the right stick, with -1 as full // left and +1 as full right. AxisRightX // AxisRightY is the up-down tilt of the right stick, with -1 as full // up and +1 as full down. AxisRightY )
type Button ¶ added in v0.0.4
type Button int
Button is a pressable switch on the gamepad. Some buttons may support analog input from 0 to +1, where 0 is fully released and +1 is fully pressed.
const ( // BtnUnknown is any button not listed in this enumeration, or any // button on a gamepad that does not have a known layout. BtnUnknown Button = iota - 1 // BtnA is the bottom button on the right side of the gamepad, usually // labelled "A" or "Cross". BtnA // BtnB is the right button on the right side of the gamepad, usually // labelled "B" or "Circle". BtnB // BtnX is the left button on the right side of the gamepad, usually // labelled "X" or "Square". BtnX // BtnY is the top button on the right side of the gamepad, usually // labelled "Y" or "Triangle". BtnY // BtnL1 is the top left button on the top of the gamepad, usually // labelled "L", "L1", or "LB". BtnL1 // BtnR1 is the top right button on the top of the gamepad, usually // labelled "R", "R1", or "RB". BtnR1 // BtnL2 is the bottom right button on the top of the gamepad, usually // labelled "ZL", "L2", or "LT". BtnL2 // BtnR2 is the bottom right button on the top of the gamepad, usually // labelled "ZR", "R2", or "RT". BtnR2 // BtnSelect is the left button in the middle of the gamepad, usually // labelled "Select", "Back", or "Minus". BtnSelect // BtnStart is the right button in the middle of the gamepad, usually // labelled "Start", "Forward", or "Plus". BtnStart // BtnLeftStick is the left directional stick, usually labelled "LSB" // or "L3". BtnLeftStick // BtnRightStick is the right directional stick, usually labelled "RSB" // or "R3". BtnRightStick // BtnDUp is the up direction on the d-pad. BtnDUp // BtnDDown is the down direction on the d-pad. BtnDDown // BtnDLeft is the left direction on the d-pad. BtnDLeft // BtnDRight is the right direction on the d-pad. BtnDRight // BtnMode is the center button in the middle of the gamepad, usually // labelled with a logo or "Share" or "Capture". BtnMode )
type Gamepad ¶
type Gamepad struct {
// contains filtered or unexported fields
}
func List ¶
func List() []*Gamepad
List returns the currently known gamepads.
The returned slice is valid until Update is called.
func (*Gamepad) Axis ¶
Axis returns the current state of the given axis on the gamepad.
If index is not in [0, NumAxis), this method returns NaN.
func (*Gamepad) AxisToIndex ¶ added in v0.0.4
AxisToIndex returns the index of the specified standard axis, or -1 if the axis is not supported by this gamepad or the axis is AxisUnknown.
func (*Gamepad) Button ¶
Button returns the current state of the given button on the gamepad.
If index is not in [0, NumButton), this method returns NaN, false.
If the platform does not support variable button presses, the value of the float is either 0 or 1.
func (*Gamepad) ButtonToIndex ¶ added in v0.0.4
ButtonToIndex returns the index of the specified standard button, or -1 if the button is not supported by this gamepad or the button is BtnUnknown.
func (*Gamepad) IndexToAxis ¶ added in v0.0.4
IndexToAxis returns the standard axis at the specified index.
func (*Gamepad) IndexToButton ¶ added in v0.0.4
IndexToButton returns the standard button at the specified index.
func (*Gamepad) Name ¶
Name returns an identifier for this gamepad. It does not change, although on Windows, multiple gamepads may have the same name.