input

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package input defines backend-neutral input snapshots and events consumed by game. It should not know about Ragnarok gameplay, rendering, or network packets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AndroidGamepadDevice added in v0.16.0

func AndroidGamepadDevice(id int, name string, connected bool)

func AndroidGamepadKey added in v0.16.0

func AndroidGamepadKey(id, key int, down bool)

func AndroidGamepadMotion added in v0.16.0

func AndroidGamepadMotion(id int, axes [GamepadAxisCount]float64, hatX, hatY float64)

func AndroidKey added in v0.16.0

func AndroidKey(code int) gpucontext.Key

AndroidKey translates Android KeyEvent keycodes to the shared input model.

func AndroidResetGamepads added in v0.16.0

func AndroidResetGamepads()

func KeyCodeName added in v0.13.0

func KeyCodeName(code KeyCode) string

KeyCodeName is the layout-independent name used by keyboard callbacks.

Types

type GamepadAxis added in v0.16.0

type GamepadAxis uint8
const (
	GamepadLeftX GamepadAxis = iota
	GamepadLeftY
	GamepadRightX
	GamepadRightY
	GamepadLeftTrigger
	GamepadRightTrigger
	GamepadAxisCount
)

func GamepadAxisFromName added in v0.16.0

func GamepadAxisFromName(name string) (GamepadAxis, bool)

type GamepadButton added in v0.16.0

type GamepadButton uint8

GamepadButton names describe positions, independent of the printed labels.

const (
	GamepadSouth GamepadButton = iota
	GamepadEast
	GamepadWest
	GamepadNorth
	GamepadLeftShoulder
	GamepadRightShoulder
	GamepadBack
	GamepadStart
	GamepadLeftStick
	GamepadRightStick
	GamepadUp
	GamepadDown
	GamepadLeft
	GamepadRight
	GamepadButtonCount
)

func AndroidGamepadButton added in v0.16.0

func AndroidGamepadButton(key int) (GamepadButton, bool)

AndroidGamepadButton maps Android KeyEvent constants to positional controls.

func GamepadButtonFromName added in v0.16.0

func GamepadButtonFromName(name string) (GamepadButton, bool)

type GamepadButtonChange added in v0.16.0

type GamepadButtonChange struct {
	Button GamepadButton
	Down   bool
}

type GamepadCapture added in v0.16.0

type GamepadCapture struct {
	Buttons [GamepadButtonCount]bool
	Pointer bool
}

GamepadCapture lets gameplay claim controls before the pointer fallback. It applies to one frame; button captures last until release in the renderer.

type GamepadFrame added in v0.16.0

type GamepadFrame struct {
	ID      string
	Name    string
	Buttons [GamepadButtonCount]bool
	Axes    [GamepadAxisCount]float64
	// Changes belongs to the receiver; draining again cannot replay or mutate it.
	Changes []GamepadButtonChange
}

GamepadFrame transfers the latest normalized controller state and the ordered button transitions collected since the previous drain. Empty ID means disconnected. Sticks use [-1,1], with negative Y pointing up; triggers use [0,1].

type GamepadSource added in v0.16.0

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

GamepadSource keeps the first controller selected until it disconnects. It has one consumer: the window loop. Create, drain and close on that thread (required by macOS). Other consumers read the shared State after SetGamepad.

func NewGamepadSource added in v0.16.0

func NewGamepadSource() (*GamepadSource, error)

func (*GamepadSource) Close added in v0.16.0

func (s *GamepadSource) Close()

func (*GamepadSource) DiscardPending added in v0.16.0

func (s *GamepadSource) DiscardPending()

DiscardPending drops queued actions at a focus boundary, even if updates were suspended while unfocused. The next drain still reports current held state.

func (*GamepadSource) DrainFrame added in v0.16.0

func (s *GamepadSource) DrainFrame() GamepadFrame

DrainFrame consumes queued changes for all controllers and returns the selected controller's frame. Call once per update, then pass it to State.SetGamepad. Diagnostics and other readers must query State instead of draining the source.

type Key

type Key int
const (
	KeyEnter Key = iota
	KeyEscape
	KeyTab
	KeyArrowUp
	KeyArrowDown
	KeyArrowLeft
	KeyArrowRight
	KeyBackspace
	KeyShift
	KeyCtrl
	KeyAlt
	KeyG
	KeyL
	Key1
	Key2
	Key3
	Key4
	Key5
	Key6
	Key7
	Key8
	Key9
	KeyQ
	KeyW
	KeyE
	KeyR
	KeyT
	KeyY
	KeyU
	KeyI
	KeyO
	KeyF1
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF12
)

type KeyCode added in v0.7.0

type KeyCode = gpucontext.Key

KeyCode identifies a physical keyboard position. Its names follow the browser KeyboardEvent.code convention (KeyW, Digit1, ArrowUp, and so on).

func KeyCodeFromName added in v0.7.0

func KeyCodeFromName(name string) (KeyCode, bool)

KeyCodeFromName resolves a layout-independent physical key name. Names use the same vocabulary as browser KeyboardEvent.code so scripts remain clear across QWERTY, AZERTY, and other layouts.

type MouseButton

type MouseButton int
const (
	MouseButtonLeft MouseButton = iota
	MouseButtonRight
)

type State

type State struct {
	MouseX  int
	MouseY  int
	MouseDX int
	MouseDY int

	WheelX float64
	WheelY float64

	TouchPoints []TouchPoint
	PinchDelta  float64
	// contains filtered or unexported fields
}

func NewState

func NewState() *State

func (*State) AddTextInput

func (s *State) AddTextInput(text string)

func (*State) AddWheel

func (s *State) AddWheel(x, y float64)

func (*State) ConsumeKeyCodePress added in v0.7.0

func (s *State) ConsumeKeyCodePress(code KeyCode) bool

ConsumeKeyCodePress reports a new physical key press once and prevents other consumers from acting on the same edge. Consumption lasts until release so native dispatch can also suppress repeats and associated text. Held state and text already collected in the snapshot are left unchanged.

func (*State) EndFrame

func (s *State) EndFrame()

func (*State) FrameID added in v0.13.0

func (s *State) FrameID() uint64

FrameID identifies the current batch of input events. UI opened by an event can use it to avoid handling that same event again during the frame update.

func (*State) GamepadChanges added in v0.16.0

func (s *State) GamepadChanges() []GamepadButtonChange

GamepadChanges reads this frame's transitions without consuming them. The returned slice is read-only and valid until EndFrame or ResetGamepad.

func (*State) GamepadConnected added in v0.16.0

func (s *State) GamepadConnected() bool

func (*State) GamepadDown added in v0.16.0

func (s *State) GamepadDown(button GamepadButton) bool

func (*State) GamepadJustPressed added in v0.16.0

func (s *State) GamepadJustPressed(button GamepadButton) bool

func (*State) GamepadJustReleased added in v0.16.0

func (s *State) GamepadJustReleased(button GamepadButton) bool

func (*State) GamepadName added in v0.16.0

func (s *State) GamepadName() string

func (*State) GamepadValue added in v0.16.0

func (s *State) GamepadValue(axis GamepadAxis) float64

func (*State) JustPressed

func (s *State) JustPressed(key Key) bool

func (*State) KeyCodeConsumed added in v0.13.0

func (s *State) KeyCodeConsumed(code KeyCode) bool

func (*State) KeyCodeDown added in v0.7.0

func (s *State) KeyCodeDown(code KeyCode) bool

func (*State) KeyCodeJustPressed added in v0.7.0

func (s *State) KeyCodeJustPressed(code KeyCode) bool

func (*State) KeyCodeJustReleased added in v0.7.0

func (s *State) KeyCodeJustReleased(code KeyCode) bool

func (*State) MouseJustPressed

func (s *State) MouseJustPressed(button MouseButton) bool

func (*State) MouseJustReleased

func (s *State) MouseJustReleased(button MouseButton) bool

func (*State) MousePressed

func (s *State) MousePressed(button MouseButton) bool

func (*State) Pressed

func (s *State) Pressed(key Key) bool

func (*State) ResetGamepad added in v0.16.0

func (s *State) ResetGamepad()

func (*State) ResetKeyboard added in v0.11.0

func (s *State) ResetKeyboard()

ResetKeyboard forgets held keys and pending keyboard input after focus loss. Releases may happen in another window and never reach us. Clear the edge history too, so cancellation does not trigger actions bound to key releases.

func (*State) ResetMouseButtons added in v0.16.0

func (s *State) ResetMouseButtons()

ResetMouseButtons cancels drags after focus loss without generating clicks.

func (*State) SetGamepad added in v0.16.0

func (s *State) SetGamepad(next GamepadFrame)

SetGamepad runs on the game thread, like SetKeyCode. Sources must not mutate State from OS callback threads. Switching controllers clears the old edges.

func (*State) SetKey

func (s *State) SetKey(key Key, pressed bool)

func (*State) SetKeyCode added in v0.7.0

func (s *State) SetKeyCode(code KeyCode, pressed bool)

func (*State) SetMouseButton

func (s *State) SetMouseButton(button MouseButton, pressed bool)

func (*State) SetMousePosition

func (s *State) SetMousePosition(x, y int)

func (*State) SetTouch

func (s *State) SetTouch(id TouchID, x, y int, pressed bool)

func (*State) TextInput

func (s *State) TextInput() string

func (*State) Update

func (s *State) Update()

type TouchID

type TouchID int64

type TouchPoint

type TouchPoint struct {
	ID TouchID
	X  int
	Y  int
}

Jump to

Keyboard shortcuts

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