Aego Русский

Input

Project Settings → Input: actions, bindings and contexts

Games read actions, not keys. An action has a name, a type and bindings; the same script works with a keyboard and a gamepad.

On this page

Actions

input version=2 {
  stack=[Gameplay]
  action {
    name=Move
    type=axis1
    bind=["Key.A/Key.D", "Key.Left/Key.Right", "Pad.LeftX"]
  }
  action {
    name=Jump
    type=button
    buffer=0.1
    bind=["Key.Space", "Pad.A"]
  }
  context {
    name=Gameplay
    actions=[Move, Jump]
  }
}

Types: button, axis1, axis2, pointer, pointerDelta.

A binding is a control or a composite:

Form Example
one control Key.Space, Mouse.Left, Pad.A, Pad.LT
negative/positive Key.A/Key.D
up/down/left/right Key.W/Key.S/Key.A/Key.D
stick Pad.LeftStick
chord Key.Z+Key.S

Options follow the control: invert, scale=2, deadzone=0.3.

interaction changes when a button fires: press (default), release, hold, tap, doubleTap, toggle. time sets the window in seconds.

Contexts

A context is a named set of actions. The stack decides what is read: higher priority first, then the last pushed.

Frames and fixed steps

Pressed in Update is true for one frame. In FixedUpdate it is true in the first fixed step after the press.

Scripts

import "aego/input"

func FixedUpdate(dt float) {
  x := input.Axis("Move")
  if grounded && input.Buffered("Jump", 0) {
    input.Consume("Jump")
    jump()
  }
}
Function
Pressed Released Held(action) bool action state
Axis(action) float axis value
Axis2(action) Vec2 2D action value
Buffered(action, window) bool, Consume(action) press buffer
PushContext PopContext SetContext context stack
PressedP ReleasedP HeldP AxisP Axis2P(player, action) per player
ActiveDevice() int, DeviceChanged() bool, Glyph(action) string devices and hints
BeginRebind(action, slot) bool, Rebinding(), RebindConflict(), ResetBinding, ResetBindings, SaveBindings menus

Rebinds and look options are player settings: they are saved in the player profile; an old user://input.aetext is imported once.

Raw keys (Down, KeyPressed, KeyReleased, MouseDown, MousePressed, MousePos, MouseWorld) stay for prototypes. Do not ship with them.

Players

players=2 gives each player their own action state.

Recording and tests

s := sdk.Actions(world)
s.Inject(40, "Jump", 1)
s.Inject(43, "Jump", 0)
s.Record(input.RecordMeta{Project: "mygame", FixedHz: 60})
data := s.StopRecording()
s.Replay(data)

A replay replaces every device. With the same scene, seed, physics settings and fixed step, a replay reproduces the run bit for bit.

Actions from modules

A module adds its own actions and contexts without importing the input module:

sdk.ProvideInputActions(r, sdk.InputActionSet{
  Actions:  []sdk.InputAction{{Name: "Kick", Type: "button", Bindings: []string{"Key.K", "Pad.Y"}}},
  Contexts: []sdk.InputContext{{Name: "Combat", Actions: []string{"Kick"}, Default: true}},
})

How module actions combine with the project:

Editor

In the editor, Escape goes to the game, so pause menus work in Play. Shift+Esc or a click outside the Game View returns input to the editor; the binding is the command Release Game Input and can be changed in the keymap.

Inject(0, action, v) applies on the next frame. Use it while game time is paused or scaled to 0, when fixed steps do not advance.