agentleFS
bmcszkbmcszk/agent-skills/skills/ebiten/input/SKILL.md

input

Skill1 starsChanged 2 months agoMITView on GitHub

Ebitengine input handling: keyboard, mouse, gamepad, touch, inpututil for just-pressed detection.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use for movement, holding a direction, charging:

    line 38
  2. Very specific:

    Use for jumping, shooting, toggling, menu selection.

    line 61
  3. Distinctive:

    Always apply a deadzone to analog sticks to avoid drift:

    line 225
  4. Distinctive:

    Use this skill only when the task clearly matches the scope described above.

    line 479
  5. Distinctive:

    Do not treat the output as a substitute for environment-specific validation, testing, or expert review.

    line 480
  6. Distinctive:

    Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

    line 481

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Input

Keyboard, mouse, gamepad, and touch input in Ebitengine.


Input API Decision Matrix

You want...Use
Continuous hold (movement, steering)ebiten.IsKeyPressed()
Single press (jump, shoot, menu select)inpututil.IsKeyJustPressed()
Single release (charge attack release)inpututil.IsKeyJustReleased()
All currently held keysebiten.AppendPressedKeys()
Mouse positionebiten.CursorPosition()
Continuous mouse button holdebiten.IsMouseButtonPressed()
Single mouse clickinpututil.IsMouseButtonJustPressed()
Mouse wheel / scrollebiten.Wheel()
Gamepad button holdebiten.IsStandardGamepadButtonPressed()
Gamepad analog stickebiten.StandardGamepadAxisValue()
Touch pressinpututil.AppendJustPressedTouchIDs()
Touch positionebiten.TouchPosition()

Keyboard

Continuous Input (Held Keys)

Use for movement, holding a direction, charging:

func (g *Game) Update() error {
    speed := 3.0
    if ebiten.IsKeyPressed(ebiten.KeyArrowRight) {
        g.player.X += speed
    }
    if ebiten.IsKeyPressed(ebiten.KeyArrowLeft) {
        g.player.X -= speed
    }
    if ebiten.IsKeyPressed(ebiten.KeyArrowUp) {
        g.player.Y -= speed
    }
    if ebiten.IsKeyPressed(ebiten.KeyArrowDown) {
        g.player.Y += speed
    }
    return nil
}

One-Shot Input (Just Pressed)

Use for jumping, shooting, toggling, menu selection. Requires inpututil package:

import "github.com/hajimehoshi/ebiten/v2/inpututil"

func (g *Game) Update() error {
    if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
        g.player.Jump()
    }
    if inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
        g.menu.Select()
    }
    if inpututil.IsKeyJustPressed(ebiten.KeyP) {
        g.paused = !g.paused
    }
    return nil
}

Just Released

if inpututil.IsKeyJustReleased(ebiten.KeySpace) {
    g.player.StopJump()
}

All Pressed Keys

pressedKeys := inpututil.AppendPressedKeys(nil)
for _, key := range pressedKeys {
    // handle each key
}

Key Constants

Common keys in ebiten package:

ConstantKey
KeyArrowUp/Down/Left/RightArrow keys
KeySpaceSpace
KeyEnterEnter
KeyEscapeEscape
KeyShiftLeft/ShiftRightShift
KeyControlLeft/ControlRightControl
KeyA through KeyZLetter keys
Key0 through Key9Number keys
KeyTabTab
KeyBackspaceBackspace

Mouse

Position

mx, my := ebiten.CursorPosition()

Returns position in logical screen coordinates (respects Layout()).

Button State

// Continuous hold (drag, aim)
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
    g.player.Shoot()
}

// Single click
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
    g.player.Dash()
}

// Release
if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) {
    g.player.StopShoot()
}

Mouse Buttons

ConstantButton
MouseButtonLeftLeft click
MouseButtonRightRight click
MouseButtonMiddleMiddle click

Mouse Wheel

xoff, yoff := ebiten.Wheel()
if yoff > 0 {
    g.camera.ZoomIn()
}
if yoff < 0 {
    g.camera.ZoomOut()
}

Returns scroll offset. yoff is vertical scroll (positive = up), xoff is horizontal scroll.


Gamepad

Detecting Gamepads

gamepadIDs := ebiten.AppendGamepadIDs(nil)
if len(gamepadIDs) == 0 {
    // no gamepad connected
}

Standard Gamepad Layout

Ebitengine uses a standard gamepad abstraction that maps common controllers (Xbox, PlayStation, Switch) to uniform button/axis IDs:

ButtonConstantTypical Mapping
StandardGamepadButtonRightBottomFace bottom (A/Cross)
StandardGamepadButtonRightRightFace right (B/Circle)
StandardGamepadButtonRightLeftFace left (X/Square)
StandardGamepadButtonRightTopFace top (Y/Triangle)
StandardGamepadButtonFrontTopLeftLeft bumper (LB/L1)
StandardGamepadButtonFrontTopRightRight bumper (RB/R1)
StandardGamepadButtonFrontBottomLeftLeft trigger (LT/L2)
StandardGamepadButtonFrontBottomRightRight trigger (RT/R2)
StandardGamepadButtonCenterLeftSelect/Back
StandardGamepadButtonCenterRightStart
StandardGamepadButtonLeftStickLeft stick press
StandardGamepadButtonRightStickRight stick press
StandardGamepadButtonDpadUp/Down/Left/RightD-pad directions

Reading Buttons

if ebiten.IsStandardGamepadButtonPressed(gamepadID, ebiten.StandardGamepadButtonRightBottom) {
    g.player.Jump()
}

if inpututil.IsStandardGamepadButtonJustPressed(gamepadID, ebiten.StandardGamepadButtonRightRight) {
    g.player.Dodge()
}

Reading Axes (Analog Sticks)

lx := ebiten.StandardGamepadAxisValue(gamepadID, ebiten.StandardGamepadAxisLeftStickHorizontal)
ly := ebiten.StandardGamepadAxisValue(gamepadID, ebiten.StandardGamepadAxisLeftStickHorizontal+1)
rx := ebiten.StandardGamepadAxisValue(gamepadID, ebiten.StandardGamepadAxisRightStickHorizontal)
ry := ebiten.StandardGamepadAxisValue(gamepadID, ebiten.StandardGamepadAxisRightStickHorizontal+1)

Axis values range from -1.0 to 1.0. Center is approximately 0.

Deadzone

Always apply a deadzone to analog sticks to avoid drift:

const deadzone = 0.25

func applyDeadzone(value float64) float64 {
    if value > -deadzone && value < deadzone {
        return 0
    }
    return value
}

lx := applyDeadzone(ebiten.StandardGamepadAxisValue(id, ebiten.StandardGamepadAxisLeftStickHorizontal))
ly := applyDeadzone(ebiten.StandardGamepadAxisValue(id, ebiten.StandardGamepadAxisLeftStickVertical))

Trigger as Axis

lt := ebiten.StandardGamepadAxisValue(id, ebiten.StandardGamepadAxisLeftStickHorizontal+4)
rt := ebiten.StandardGamepadAxisValue(id, ebiten.StandardGamepadAxisLeftStickHorizontal+5)

Trigger axes return 0.0 (released) to 1.0 (fully pressed).


Touch

For mobile and touchscreen support:

func (g *Game) Update() error {
    // Just pressed touches
    touchIDs := inpututil.AppendJustPressedTouchIDs(nil)
    for _, id := range touchIDs {
        x, y := ebiten.TouchPosition(id)
        g.handleTouchPress(x, y)
    }

    // Active touches
    activeIDs := inpututil.AppendPressedTouchIDs(nil)
    for _, id := range activeIDs {
        x, y := ebiten.TouchPosition(id)
        g.handleTouchDrag(x, y)
    }

    // Just released touches
    releasedIDs := inpututil.AppendJustReleasedTouchIDs(nil)
    for _, id := range releasedIDs {
        x, y := ebiten.TouchPosition(id)
        g.handleTouchRelease(x, y)
    }

    return nil
}

Touch Functions

FunctionPurpose
inpututil.AppendJustPressedTouchIDs(ids)IDs of touches that started this tick
inpututil.AppendPressedTouchIDs(ids)IDs of currently active touches
inpututil.AppendJustReleasedTouchIDs(ids)IDs of touches that ended this tick
ebiten.TouchPosition(id)(x, y) position of specific touch
inpututil.TouchPressDuration(id)How many ticks the touch has been held

Input Abstraction Pattern

Decouple physical inputs from game actions using an action mapper:

type InputAction int

const (
    ActionMoveLeft InputAction = iota
    ActionMoveRight
    ActionMoveUp
    ActionMoveDown
    ActionJump
    ActionShoot
    ActionPause
    ActionMenuSelect
)

type InputMapper struct {
    keyBindings      map[InputAction][]ebiten.Key
    mouseBindings    map[InputAction][]ebiten.MouseButton
    gamepadBindings  map[InputAction][]ebiten.StandardGamepadButton
}

func NewInputMapper() *InputMapper {
    return &InputMapper{
        keyBindings: map[InputAction][]ebiten.Key{
            ActionMoveLeft:  {ebiten.KeyArrowLeft, ebiten.KeyA},
            ActionMoveRight: {ebiten.KeyArrowRight, ebiten.KeyD},
            ActionMoveUp:    {ebiten.KeyArrowUp, ebiten.KeyW},
            ActionMoveDown:  {ebiten.KeyArrowDown, ebiten.KeyS},
            ActionJump:      {ebiten.KeySpace},
            ActionShoot:     {ebiten.KeyJ},
            ActionPause:     {ebiten.KeyEscape, ebiten.KeyP},
            ActionMenuSelect: {ebiten.KeyEnter},
        },
        gamepadBindings: map[InputAction][]ebiten.StandardGamepadButton{
            ActionJump:       {ebiten.StandardGamepadButtonRightBottom},
            ActionShoot:      {ebiten.StandardGamepadButtonRightRight},
            ActionPause:      {ebiten.StandardGamepadButtonCenterRight},
            ActionMenuSelect: {ebiten.StandardGamepadButtonRightBottom},
        },
    }
}

func (m *InputMapper) IsActionPressed(action InputAction) bool {
    for _, key := range m.keyBindings[action] {
        if ebiten.IsKeyPressed(key) {
            return true
        }
    }
    for _, btn := range m.gamepadBindings[action] {
        for _, id := range ebiten.AppendGamepadIDs(nil) {
            if ebiten.IsStandardGamepadButtonPressed(id, btn) {
                return true
            }
        }
    }
    return false
}

func (m *InputMapper) IsActionJustPressed(action InputAction) bool {
    for _, key := range m.keyBindings[action] {
        if inpututil.IsKeyJustPressed(key) {
            return true
        }
    }
    for _, btn := range m.gamepadBindings[action] {
        for _, id := range ebiten.AppendGamepadIDs(nil) {
            if inpututil.IsStandardGamepadButtonJustPressed(id, btn) {
                return true
            }
        }
    }
    return false
}

Using the Mapper

func (g *Game) Update() error {
    if g.input.IsActionPressed(ActionMoveLeft) {
        g.player.X -= g.player.Speed
    }
    if g.input.IsActionJustPressed(ActionJump) {
        g.player.Jump()
    }
    return nil
}

ebitengine-input Library

For a more complete Godot-inspired action input system:

import "github.com/quasilyte/ebitengine-input"

type inputContext struct {
    inp *input.Input
}

func newInput() *inputContext {
    inp := input.New(input.SystemConfig{
        Keys: input.KeysConfig{
            MaxBindingsPerAction: 4,
        },
    })
    return &inputContext{inp: inp}
}

Handling Multiple Input Sources

func (g *Game) Update() error {
    // Check keyboard first, then gamepad, then touch
    if g.input.IsActionJustPressed(ActionJump) ||
        g.checkTouchJump() {
        g.player.Jump()
    }

    // Movement from any source
    dx, dy := g.getMovementVector()
    g.player.Move(dx, dy)

    return nil
}

Input Recording (for replays)

type InputEvent struct {
    Tick    int
    Actions []InputAction
}

type InputRecorder struct {
    events []InputEvent
    tick   int
}

func (r *InputRecorder) Record(mapper *InputMapper) {
    var actions []InputAction
    for action := ActionMoveLeft; action <= ActionMenuSelect; action++ {
        if mapper.IsActionPressed(action) {
            actions = append(actions, action)
        }
    }
    if len(actions) > 0 {
        r.events = append(r.events, InputEvent{Tick: r.tick, Actions: actions})
    }
    r.tick++
}

Anti-Patterns

Don'tDo
Use IsKeyPressed() for single actionsUse inpututil.IsKeyJustPressed() for one-shot events
Poll gamepad without checking connectionCheck AppendGamepadIDs() first
Skip deadzone on analog sticksApply a 0.15-0.25 deadzone always
Hard-code key bindingsUse an input mapper / action system
Handle only keyboardSupport gamepad and touch where possible
Read CursorPosition() in Draw()Read input only in Update()
Mix input reading with game logicSeparate input polling from action handling
Ignore touch input for mobile targetsUse touch IDs for multi-touch support
Create new slices in hot path for AppendPressedKeysReuse slice: keys = inpututil.AppendPressedKeys(keys[:0])

When to Use

This skill is applicable when implementing or modifying input handling in an Ebitengine game: keyboard, mouse, gamepad, or touch.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.