controller

package
v0.0.0-...-4d18667 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package controller lets you poll controllers, their buttons their axes and let them rumble.

Index

Constants

All a possible axes.

All possible buttons.

Variables

All contains all available controllers.

Functions

func Count

func Count() int

Count returns the number of Joysticks.

func DispatchAxisEvent

func DispatchAxisEvent(id sdl.JoystickID, a uint8, value int16)

DispatchAxisEvent triggers an axis event. This func should not be called manually.

func DispatchButtonEvent

func DispatchButtonEvent(id sdl.JoystickID, b uint8, state uint8)

DispatchButtonEvent triggers a button event. This func should not be called manually.

Types

type Axis

type Axis int

Axis is a controller's axis.

type Button

type Button int

Button is a controller's button.

type Controller

type Controller struct {
	ID        int
	Name      string
	Connected bool
	// contains filtered or unexported fields
}

Controller is a Controller, Gamepad or Joystick.

func Close

func Close(id sdl.JoystickID) *Controller

Close closes the joystick for the given id and returns the now disconnected controller.

func Open

func Open(id sdl.JoystickID) *Controller

Open opens the joystick for the given id and returns it.

func (*Controller) ClearListener

func (c *Controller) ClearListener()

ClearListener removes the Listener for the controller.

func (*Controller) Rumble

func (c *Controller) Rumble(strength float32, duration uint32) error

Rumble lets the controller vibrate for a given time and strength.

func (*Controller) SetListener

func (c *Controller) SetListener(l *Listener)

SetListener sets the Listener that will get notified when controller events occur.

type Listener

type Listener struct {
	// OnButtonDown gets called when a button is pressed.
	OnButtonDown func(b Button)
	// OnButtonUp gets called when a button is released.
	OnButtonUp func(b Button)
	// OnAxisMoved gets called when a axis is moved.
	OnAxisMoved func(a Axis, value float64)
	// OnConnect gets called when the controller connects.
	OnConnect func()
	// OnDisconnectConnect gets called when the controller disconnects.
	OnDisconnect func()
}

Listener is used as a scaffold to listen to controller events.

Jump to

Keyboard shortcuts

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