pads

package
v1.17.5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pads is the manager of the gamepads of an app (SPEC §28.2): it takes the pads and the raw reports that a platform backend gives (internal/platform.Gamepads), finds each pad's mapping in the table (internal/gamepaddb), keeps the state of the buttons and axes of the standard layout and tells the listeners, and turns the buttons into key events. The engine owns one manager for the app, so a pad moves the focus of every app, whether it imports package gamepad or not; package gamepad is the public face of it.

A manager belongs to the UI thread, like the rest of the framework: the platform hands its reports over with Post.

Flutter: no counterpart

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyIDs

func KeyIDs(b gamepaddb.Button) (physical, logical uint64, ok bool)

KeyIDs returns the physical and logical key IDs that the button makes, and whether it makes a key at all.

Flutter: no counterpart

func TriggerKeyIDs

func TriggerKeyIDs(i int) (physical, logical uint64)

TriggerKeyIDs returns the physical and logical key IDs of the left (0) or right (1) trigger.

Flutter: no counterpart

Types

type Event

type Event struct {
	Pad  *Pad
	Time time.Duration
	Kind EventKind
	// Button is the button of a ButtonDown or ButtonUp.
	Button gamepaddb.Button
	// Axis and Value are the axis of an AxisMotion and its new raw value.
	Axis  gamepaddb.Axis
	Value int16
}

Event is a change of the buttons or axes of a pad.

Flutter: no counterpart

type EventKind

type EventKind uint8

EventKind says what an Event reports.

Flutter: no counterpart

const (
	// ButtonDown is a button that went down.
	//
	// Flutter: no counterpart
	ButtonDown EventKind = iota
	// ButtonUp is a button that went up.
	//
	// Flutter: no counterpart
	ButtonUp
	// AxisMotion is an axis that has a new value.
	//
	// Flutter: no counterpart
	AxisMotion
)

type Host

type Host interface {
	PadManager() *Manager
	// UsePads says that the app uses package gamepad: the host starts a manager that waits for it, and wakes the extras of the
	// service (SPEC §28.2, "Decided in step 36.1"). It is called on the UI thread, and may be called again.
	UsePads()
}

Host is implemented by the host of the dispatcher (the engine) and found through ui.PlatformDispatcher.HostAs: it gives the manager of the app, or nil when the platform has no gamepads.

Flutter: no counterpart

type Key

type Key struct {
	Time time.Duration
	Down bool
	// Physical and Logical are the IDs of the key (services.PhysicalKeyboardKey and services.LogicalKeyboardKey).
	Physical, Logical uint64
	// DirectionalPad says that the key is an arrow of the D-pad, and not a game button.
	DirectionalPad bool
}

Key is a key event that a pad makes (SPEC §28.2, "Pads as keys").

Flutter: no counterpart

type Manager

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

Manager keeps the pads of an app.

Flutter: no counterpart

func New

func New(plat platform.Gamepads, opts Opts) *Manager

New makes the manager of the gamepad service plat. It does nothing until Start.

Flutter: no counterpart

func (*Manager) AddListener

func (m *Manager) AddListener(fn func()) (remove func())

AddListener adds a function that is called when a pad is connected or removed, and returns the function that removes it.

Flutter: no counterpart

func (*Manager) AddMapping

func (m *Manager) AddMapping(line string) (int, error)

AddMapping adds one mapping line, like AddMappings, whatever its platform: field says.

Flutter: no counterpart

func (*Manager) AddMappings

func (m *Manager) AddMappings(text string) (int, error)

AddMappings adds mappings in the community's format (one line each: "GUID,name,a:b0,b:b1,..."; lines with a platform: field for another platform are left out) and gives the pads that had none the chance to take one. It returns the number of mappings that are new. An error tagged GamepadMappingInvalid says the first line that could not be read; the lines before it are added.

Flutter: no counterpart

func (*Manager) At

func (m *Manager) At(i int) *Pad

At returns the i-th connected pad that has a mapping (0 to Count()-1).

Flutter: no counterpart

func (*Manager) Available

func (m *Manager) Available() bool

Available says whether the platform has a gamepad service at all.

Flutter: no counterpart

func (*Manager) Count

func (m *Manager) Count() int

Count is the number of connected pads that have a mapping, and At the pad that came i-th: a loop over them allocates nothing.

Flutter: no counterpart

func (*Manager) KeyEvents

func (m *Manager) KeyEvents() bool

KeyEvents says whether the pads make key events.

Flutter: no counterpart

func (*Manager) PadAdded

func (m *Manager) PadAdded(info platform.PadInfo)

PadAdded implements platform.PadHandler.

func (*Manager) PadBattery

func (m *Manager) PadBattery(b platform.PadBattery)

PadBattery implements platform.PadExtrasHandler.

func (*Manager) PadEvents

func (m *Manager) PadEvents(events []platform.PadEvent)

PadEvents implements platform.PadHandler.

func (*Manager) PadRemoved

func (m *Manager) PadRemoved(id platform.PadID)

PadRemoved implements platform.PadHandler.

func (*Manager) PadSensor

func (m *Manager) PadSensor(s platform.PadSensor)

PadSensor implements platform.PadExtrasHandler.

func (*Manager) PadTouch

func (m *Manager) PadTouch(t platform.PadTouch)

PadTouch implements platform.PadExtrasHandler.

func (*Manager) Pads

func (m *Manager) Pads() []*Pad

Pads returns the connected pads that have a mapping, in the order they were connected. The slice is a copy.

Flutter: no counterpart

func (*Manager) SetKeyEvents

func (m *Manager) SetKeyEvents(on bool)

SetKeyEvents turns the key events of the pads on or off. They are on at first, when the manager was given a function for them.

Flutter: no counterpart

func (*Manager) Start

func (m *Manager) Start() error

Start begins to look for pads. Starting a started manager does nothing.

Flutter: no counterpart

func (*Manager) Stop

func (m *Manager) Stop()

Stop ends the search and lets go of every pad.

Flutter: no counterpart

func (*Manager) Table

func (m *Manager) Table() *gamepaddb.Table

Table returns the table of mappings, made on first use.

Flutter: no counterpart

func (*Manager) Wake

func (m *Manager) Wake() error

Wake says that the app uses package gamepad. It starts the manager if it is not started (the mode that waits for the app) and wakes the extras of the platform service, if it has any (platform.PadExtras): until then the service only reads. Waking a manager that is awake does nothing.

Flutter: no counterpart

type Opts

type Opts struct {
	// Keys receives the key events of the pads; nil turns key events off for good.
	Keys func(Key)
	// Logger receives the notes of the manager; nil logs nothing.
	Logger *slog.Logger
	// Getenv is passed to the table of mappings for the hint: fields; nil means os.Getenv.
	Getenv func(string) string
	// SDKVersion is the version of Android, for the sdk>= fields of the table; 0 elsewhere.
	SDKVersion int
}

Opts are the options of a manager.

Flutter: no counterpart

type Pad

type Pad struct {

	// Wrapper is a place for the public type that wraps the pad, so that the same pad is the same value for the app.
	Wrapper any
	// contains filtered or unexported fields
}

Pad is a connected gamepad that has a mapping to the standard layout.

Flutter: no counterpart

func (*Pad) AddListener

func (p *Pad) AddListener(fn func(Event)) (remove func())

AddListener adds a function that is called, on the UI thread, with every change of a button or axis of the pad, and returns the function that removes it. A listener may add and remove listeners.

Flutter: no counterpart

func (*Pad) AddSensorListener

func (p *Pad) AddSensorListener(fn func(SensorReading)) (remove func())

AddSensorListener adds a function that is called, on the UI thread, with every reading of the sensors, and returns the function that removes it. A listener may add and remove listeners.

Flutter: no counterpart

func (*Pad) AddTouchListener

func (p *Pad) AddTouchListener(fn func(Touch)) (remove func())

AddTouchListener adds a function that is called, on the UI thread, when a finger goes down, moves or goes up, and returns the function that removes it. A listener may add and remove listeners.

Flutter: no counterpart

func (*Pad) AxisChanged

func (p *Pad) AxisChanged(t int64, a gamepaddb.Axis, v int16)

AxisChanged implements gamepaddb.Sink.

func (*Pad) Battery

func (p *Pad) Battery() int

Battery is the charge of the pad from 0 to 100, or -1 when it is not known.

Flutter: no counterpart

func (*Pad) ButtonChanged

func (p *Pad) ButtonChanged(t int64, b gamepaddb.Button, down bool)

ButtonChanged implements gamepaddb.Sink.

func (*Pad) CanRumble

func (p *Pad) CanRumble() bool

CanRumble says whether the pad has motors, as its platform reported.

Flutter: no counterpart

func (*Pad) CanRumbleTriggers

func (p *Pad) CanRumbleTriggers() bool

CanRumbleTriggers says whether the pad has motors in its triggers.

Flutter: no counterpart

func (*Pad) Connected

func (p *Pad) Connected() bool

Connected says whether the pad is still there.

Flutter: no counterpart

func (*Pad) EnableSensors

func (p *Pad) EnableSensors(on bool) error

EnableSensors turns the sensors of the pad on or off: a pad reports its sensors only while they are on, which saves its battery. It fails with GamepadSensorsUnavailable when the pad has none or the platform cannot turn them on.

Flutter: no counterpart

func (*Pad) FaceStyle

func (p *Pad) FaceStyle() gamepaddb.FaceStyle

FaceStyle is how the face buttons of the pad are labelled.

Flutter: no counterpart

func (*Pad) GUID

func (p *Pad) GUID() gamepaddb.GUID

GUID identifies the model of the pad.

Flutter: no counterpart

func (*Pad) HasAxis

func (p *Pad) HasAxis(a gamepaddb.Axis) bool

HasAxis says whether the pad has the axis.

Flutter: no counterpart

func (*Pad) HasButton

func (p *Pad) HasButton(b gamepaddb.Button) bool

HasButton says whether the pad has the button.

Flutter: no counterpart

func (*Pad) HasLED

func (p *Pad) HasLED() bool

HasLED says whether the pad has a light that can be set.

Flutter: no counterpart

func (*Pad) HasSensors

func (p *Pad) HasSensors() bool

HasSensors says whether the pad has a gyroscope and an accelerometer.

Flutter: no counterpart

func (*Pad) ID

func (p *Pad) ID() platform.PadID

ID is the platform's number of the pad.

Flutter: no counterpart

func (*Pad) Kind

func (p *Pad) Kind() gamepaddb.Kind

Kind is the model of the pad.

Flutter: no counterpart

func (*Pad) LatestSensor

func (p *Pad) LatestSensor(kind platform.PadSensorKind) (SensorReading, bool)

LatestSensor returns the last reading of the sensor of the kind, if there is one.

Flutter: no counterpart

func (*Pad) Mapping

func (p *Pad) Mapping() string

Mapping is the mapping text of the pad ("a:b0,b:b1,..."), or "" for a pad that reports the standard layout.

Flutter: no counterpart

func (*Pad) Name

func (p *Pad) Name() string

Name is the name of the pad.

Flutter: no counterpart

func (*Pad) Path

func (p *Pad) Path() string

Path says where the pad is on the system, or "".

Flutter: no counterpart

func (*Pad) Power

func (p *Pad) Power() Power

Power returns the state of the pad's battery.

Flutter: no counterpart

func (*Pad) Rumble

func (p *Pad) Rumble(low, high uint16, d time.Duration) error

Rumble turns the pad's motors for d; see platform.Gamepads.Rumble.

Flutter: no counterpart

func (*Pad) RumbleTriggers

func (p *Pad) RumbleTriggers(left, right uint16, d time.Duration) error

RumbleTriggers turns the motors of the pad's triggers for d.

Flutter: no counterpart

func (*Pad) SensorRate

func (p *Pad) SensorRate() float32

SensorRate is how many readings of each sensor the pad makes in a second, or 0 when it does not say.

Flutter: no counterpart

func (*Pad) SensorsEnabled

func (p *Pad) SensorsEnabled() bool

SensorsEnabled says whether the sensors are on.

Flutter: no counterpart

func (*Pad) SetLED

func (p *Pad) SetLED(r, g, b uint8) error

SetLED sets the colour of the pad's light.

Flutter: no counterpart

func (*Pad) State

func (p *Pad) State() State

State returns the buttons and axes of the pad now.

Flutter: no counterpart

func (*Pad) Touches

func (p *Pad) Touches() []Touch

Touches returns the fingers that are on the touchpads of the pad now.

Flutter: no counterpart

func (*Pad) Touchpads

func (p *Pad) Touchpads() int

Touchpads is the number of touchpads of the pad.

Flutter: no counterpart

type Power

type Power struct {
	State platform.PadPowerState
	// Percent is from 0 to 100, or -1 when it is not known.
	Percent int
}

Power is what a pad says about its battery.

Flutter: no counterpart

type SensorReading

type SensorReading struct {
	Pad *Pad
	// Time is when the report that held the reading arrived, and SensorTime when the sensor made it, on its own clock.
	Time, SensorTime time.Duration
	Kind             platform.PadSensorKind
	// Values are the three components: rad/s for the gyroscope, m/s² (gravity included) for the accelerometer.
	Values [3]float32
}

SensorReading is a reading of a motion sensor of a pad (SPEC §28.4, which makes the type public in step 31.7).

Flutter: no counterpart

type State

type State struct {

	// Axes are the raw values of the axes, from gamepaddb.AxisMin to gamepaddb.AxisMax (the triggers from 0).
	Axes [gamepaddb.AxisCount]int16
	// contains filtered or unexported fields
}

State is the buttons and axes of a pad now.

Flutter: no counterpart

func (State) Down

func (s State) Down(b gamepaddb.Button) bool

Down says whether the button is down.

Flutter: no counterpart

type Touch

type Touch struct {
	Pad *Pad
	// Time is when the pad reported the finger, on the system's monotonic clock.
	Time time.Duration
	// Touchpad and Finger number the touchpad and the finger, from 0. A PlayStation pad has one touchpad and two fingers.
	Touchpad, Finger int
	// Down says that the finger is on the touchpad. X and Y are from 0 to 1, from the top left corner, and where the finger
	// left when it is not down; Pressure is 1 for a finger that is down and 0 for one that is not.
	Down           bool
	X, Y, Pressure float32
}

Touch is a finger on a touchpad of a pad.

Flutter: no counterpart

Jump to

Keyboard shortcuts

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