gamepad

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: MIT Imports: 11 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Update

func Update() error

Update updates the state of the known gamepads.

This function should be called before gamepad states are checked on each frame.

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
)

func (Axis) String added in v0.0.4

func (i Axis) String() string

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
)

func (Button) String added in v0.0.4

func (i Button) String() string

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

func (g *Gamepad) Axis(index int) float32

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

func (g *Gamepad) AxisToIndex(axis Axis) int

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

func (g *Gamepad) Button(index int) (float32, bool)

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

func (g *Gamepad) ButtonToIndex(btn Button) int

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

func (g *Gamepad) IndexToAxis(index int) Axis

IndexToAxis returns the standard axis at the specified index.

func (*Gamepad) IndexToButton added in v0.0.4

func (g *Gamepad) IndexToButton(index int) Button

IndexToButton returns the standard button at the specified index.

func (*Gamepad) Name

func (g *Gamepad) Name() string

Name returns an identifier for this gamepad. It does not change, although multiple gamepads may have the same name.

func (*Gamepad) NumAxis

func (g *Gamepad) NumAxis() int

NumAxis returns the number of axes on the gamepad.

func (*Gamepad) NumButton

func (g *Gamepad) NumButton() int

NumButton returns the number of buttons on the gamepad.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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