userinput

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package userinput translates real hardware input from the user's computer, to the emulated console. It abstracts real user interface to the emulated interface.

The Controllers type processes userinput Events (input from a gamepad for example) with the HandleUserInput function. That input is translated into an event understood by the emulation (paddle left for example).

Many emulations can be attached to a single Controllers type with the AddInputHandler(). However, the DrivenEvent mechanism in the riot.ports package is a better way to do this in many instances.

Index

Constants

View Source
const ThumbstickDeadzone = 10000

quite a large deadzone for the thumbstick

Variables

This section is empty.

Functions

This section is empty.

Types

type Controllers

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

Controllers keeps track of hardware userinput options.

func NewControllers added in v0.16.0

func NewControllers(h HandleInput) *Controllers

Controllers is the preferred method of initialisation for the Controllers type.

func (*Controllers) HandleUserInput

func (c *Controllers) HandleUserInput(ev Event) (bool, error)

HandleUserInput deciphers the Event and forwards the input to the Atari 2600 player ports.

Returns True if event has been handled/recognised by at least one of the registered input handlers.

func (*Controllers) Swap added in v0.28.0

func (c *Controllers) Swap() bool

Swap exchanges which controls affects which player port. For example, the cursor keys on the keyboard will normally control the left player. However, when swapped, the cursor keys will control the right player

Returns true if the ports are now swapped and false if the ports are in the original state

type DPadDirection

type DPadDirection int

DPadDirection indentifies the direction the dpad is being pressed.

const (
	DPadNone DPadDirection = iota
	DPadCentre
	DPadUp
	DPadDown
	DPadLeft
	DPadRight
	DPadLeftUp
	DPadLeftDown
	DPadRightUp
	DPadRightDown
)

List of valid DPadDirection values.

type Event

type Event interface{}

Event represents all the different type of events that can occur in the GUI.

Events are the things that happen in the GUI, as a result of user interaction, and sent over a registered event channel.

type EventGamepadButton

type EventGamepadButton struct {
	ID     plugging.PortID
	Button GamepadButton
	Down   bool
}

EventGamepadButton data is generated by any of a game controller's buttons.

type EventGamepadDPad

type EventGamepadDPad struct {
	ID        plugging.PortID
	Direction DPadDirection
}

EventGamepadDpad data is generated by a game controller's DPad.

type EventGamepadThumbstick

type EventGamepadThumbstick struct {
	ID plugging.PortID

	// the axis being moved
	Thumbstick GamepadThumbstick

	// value from hardware controller should use full range
	Horiz int16
	Vert  int16
}

EventGamepadThumbstick data is generated by a gamepad's analogue sticks.

type EventGamepadTrigger

type EventGamepadTrigger struct {
	ID plugging.PortID

	// the trigger being flexed
	Trigger GamepadTrigger

	// value from hardware controller should use full range
	Amount int16
}

EventGamepadAnalogue data is generated by a gamepads analogue triggers.

type EventKeyboard

type EventKeyboard struct {
	Key  string
	Down bool
	Mod  KeyMod
}

EventKeyboard data is generated by the system keyboard.

type EventMouseButton

type EventMouseButton struct {
	Button MouseButton
	Down   bool
}

EventMouseButton data is generated by any of the system mouse buttons.

type EventMouseMotion

type EventMouseMotion struct {
	X int16
	Y int16
}

EventMouseMotion data is generated by the motion of the system mouse.

type EventMouseWheel added in v0.15.0

type EventMouseWheel struct {
	Delta float32
	Mod   KeyMod
}

EventMouseWheel data is generated by the mouse wheel (jog wheel).

type EventQuit

type EventQuit struct{}

EventQuit is sent, for example, when the GUI window is closed.

type EventStelladaptor added in v0.21.0

type EventStelladaptor struct {
	ID plugging.PortID

	// joystick, paddle and driving controllers all alter the horiz/vert values
	Horiz int16
	Vert  int16
}

EventStelladaptor data is generated by the stelladaptor.

type GamepadButton

type GamepadButton int

GamepadButton identifies a gamepad button.

const (
	GamepadButtonNone GamepadButton = iota
	GamepadButtonBack
	GamepadButtonStart
	GamepadButtonA
	GamepadButtonB
	GamepadButtonBumperLeft
	GamepadButtonBumperRight
	GamepadButtonGuide
)

List of valid GamepadButtons.

type GamepadThumbstick

type GamepadThumbstick int

GamepadThumbstick identifies the gamepad thumbstick.

const (
	GamepadThumbstickLeft GamepadThumbstick = iota
	GamepadThumbstickRight
)

List of GamepadAxis values.

type GamepadTrigger

type GamepadTrigger int

GamepadTrigger identifies the gamepad triggers.

const (
	GamepadTriggerNone GamepadTrigger = iota
	GamepadTriggerLeft
	GamepadTriggerRight
)

List of GamepadTrigger values.

type HandleInput

type HandleInput interface {
	// PeripheralID identifies the device currently attached to the port.
	PeripheralID(id plugging.PortID) plugging.PeripheralID

	// HandleInputEvent forwards the Event and EventData to the device connected to the
	// specified PortID.
	//
	// Returns true if the port understood and handled the event.
	HandleInputEvent(ports.InputEvent) (bool, error)
}

HandleInput conceptualises data being sent to the console ports.

type KeyMod

type KeyMod int

KeyMod identifies.

const (
	KeyModNone KeyMod = iota
	KeyModShift
	KeyModCtrl
	KeyModAlt
)

list of valud key modifiers.

type MouseButton

type MouseButton int

MouseButton identifies the mouse button.

const (
	MouseButtonNone MouseButton = iota
	MouseButtonLeft
	MouseButtonRight
	MouseButtonMiddle
)

List of valid MouseButtonIDs.

Jump to

Keyboard shortcuts

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