# aego/input

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

Prefer actions (`Pressed("Jump")`, `Axis2("Move")`) to raw keys: actions are bound in the project, can be rebound by players and work with every device. The `P` variants read one player. The documentation sandbox has no devices, so the example reads zero values and reports that no device was used; in a game the same code moves the node. See [Input](/input.md).

## Choose an operation

| Task | Start with |
|---|---|
| React to an action | Pressed for an edge, Down for holding, Axis/Axis2 for movement |
| Read one player | The matching `P` variant and the player index |
| Control overlapping UI/game bindings | Input contexts and action consumption |
| Offer rebinding | Rebind operations and glyphs, not hard-coded keyboard labels |
| Inspect a device | ActiveDevice and low-level key, mouse or gamepad operations |

Action-based Pressed is delivered to the first fixed step after a press, including a press on a render frame with no fixed step. Subsequent fixed steps do not repeat that edge. Check input contexts if another consumer handles it first. Raw KeyPressed describes a frame edge; do not assume that every low-level operation has the action queue's contract.

The Run button below demonstrates script execution and zero-device results only. To test movement with real input, follow the [Input guide](/input.md) in a desktop project. Resetting a script playground is not a reset of a physics world.

## Example

```aes run
package demo

import (
    "aego/input"
    "aego/log"
)

script Player {
    @export var Speed float = 4

    var jumps int
    var frames int

    func Update(dt float) {
        move := input.Axis2("Move")
        node.SetPosition(node.Position() + move * Speed * dt)
        if input.Pressed("Jump") {
            jumps++
        }
        if input.Down(input.KeyF1) || input.MousePressed(input.MouseLeft) {
            log.Info("cursor at " + string(input.MouseWorld().X) + ", " + string(input.MouseWorld().Y))
        }
        frames++
        if frames % 60 == 0 {
            device := input.ActiveDevice()
            if device < 0 {
                log.Info("no input yet; move " + string(move.X) + ", " + string(move.Y) + ", jumps " + string(jumps))
            } else {
                log.Info("device " + string(device) + ", jump is " + input.Glyph("Jump"))
            }
        }
    }
}
```

## ActiveDevice

```
func ActiveDevice() int
```

Returns the device player 0 used last: -1 none, 0 keyboard and mouse, 1 to 4 a gamepad.

## Axis

```
func Axis(action string) float
```

Returns the value of an axis action from -1 to 1, or the press strength of a button action.

## Axis2

```
func Axis2(action string) Vec2
```

Returns a 2D action as a vector no longer than 1; Y grows downward like the 2D world.

## Axis2P

```
func Axis2P(player int, action string) Vec2
```

Is Axis2 for one player.

## AxisP

```
func AxisP(player int, action string) float
```

Is Axis for one player.

## BeginRebind

```
func BeginRebind(action string, slot int) bool
```

Waits for the next key, button or stick and binds it to the slot of the action. Escape cancels.

## Buffered

```
func Buffered(action string, window float) bool
```

Reports whether the action was pressed in the last window game seconds and not consumed. A window of 0 uses the action's buffer setting.

## Button

```
enum Button
```

Button is a mouse button.

## Consume

```
func Consume(action string)
```

Clears the press and the buffer of the action, so later readers this frame do not see it.

## DeviceChanged

```
func DeviceChanged() bool
```

Is true for the frame a gamepad was connected or removed.

## Down

```
func Down(key aego/input.Key) bool
```

Reports whether a raw key is held. For prototypes; release builds use actions.

## Glyph

```
func Glyph(action string) string
```

Returns the binding of the action for the active device as text, like [Space] or [A].

## Held

```
func Held(action string) bool
```

Reports whether the action is active.

## HeldP

```
func HeldP(player int, action string) bool
```

Is Held for one player.

## Key

```
enum Key
```

Key is a physical key, independent of the keyboard layout. Prefer actions; raw keys are for prototypes.

## KeyA

```
const KeyA enum:aego/input.Key
```

The A key.

## KeyB

```
const KeyB enum:aego/input.Key
```

The B key.

## KeyBackspace

```
const KeyBackspace enum:aego/input.Key
```

The Backspace key.

## KeyC

```
const KeyC enum:aego/input.Key
```

The C key.

## KeyCapsLock

```
const KeyCapsLock enum:aego/input.Key
```

The CapsLock key.

## KeyD

```
const KeyD enum:aego/input.Key
```

The D key.

## KeyDelete

```
const KeyDelete enum:aego/input.Key
```

The Delete key.

## KeyDigit0

```
const KeyDigit0 enum:aego/input.Key
```

The Digit0 key.

## KeyDigit1

```
const KeyDigit1 enum:aego/input.Key
```

The Digit1 key.

## KeyDigit2

```
const KeyDigit2 enum:aego/input.Key
```

The Digit2 key.

## KeyDigit3

```
const KeyDigit3 enum:aego/input.Key
```

The Digit3 key.

## KeyDigit4

```
const KeyDigit4 enum:aego/input.Key
```

The Digit4 key.

## KeyDigit5

```
const KeyDigit5 enum:aego/input.Key
```

The Digit5 key.

## KeyDigit6

```
const KeyDigit6 enum:aego/input.Key
```

The Digit6 key.

## KeyDigit7

```
const KeyDigit7 enum:aego/input.Key
```

The Digit7 key.

## KeyDigit8

```
const KeyDigit8 enum:aego/input.Key
```

The Digit8 key.

## KeyDigit9

```
const KeyDigit9 enum:aego/input.Key
```

The Digit9 key.

## KeyDown

```
const KeyDown enum:aego/input.Key
```

The Down key.

## KeyE

```
const KeyE enum:aego/input.Key
```

The E key.

## KeyEnd

```
const KeyEnd enum:aego/input.Key
```

The End key.

## KeyEnter

```
const KeyEnter enum:aego/input.Key
```

The Enter key.

## KeyEscape

```
const KeyEscape enum:aego/input.Key
```

The Escape key.

## KeyF

```
const KeyF enum:aego/input.Key
```

The F key.

## KeyF1

```
const KeyF1 enum:aego/input.Key
```

The F1 key.

## KeyF10

```
const KeyF10 enum:aego/input.Key
```

The F10 key.

## KeyF11

```
const KeyF11 enum:aego/input.Key
```

The F11 key.

## KeyF12

```
const KeyF12 enum:aego/input.Key
```

The F12 key.

## KeyF2

```
const KeyF2 enum:aego/input.Key
```

The F2 key.

## KeyF3

```
const KeyF3 enum:aego/input.Key
```

The F3 key.

## KeyF4

```
const KeyF4 enum:aego/input.Key
```

The F4 key.

## KeyF5

```
const KeyF5 enum:aego/input.Key
```

The F5 key.

## KeyF6

```
const KeyF6 enum:aego/input.Key
```

The F6 key.

## KeyF7

```
const KeyF7 enum:aego/input.Key
```

The F7 key.

## KeyF8

```
const KeyF8 enum:aego/input.Key
```

The F8 key.

## KeyF9

```
const KeyF9 enum:aego/input.Key
```

The F9 key.

## KeyG

```
const KeyG enum:aego/input.Key
```

The G key.

## KeyH

```
const KeyH enum:aego/input.Key
```

The H key.

## KeyHome

```
const KeyHome enum:aego/input.Key
```

The Home key.

## KeyI

```
const KeyI enum:aego/input.Key
```

The I key.

## KeyInsert

```
const KeyInsert enum:aego/input.Key
```

The Insert key.

## KeyJ

```
const KeyJ enum:aego/input.Key
```

The J key.

## KeyK

```
const KeyK enum:aego/input.Key
```

The K key.

## KeyKP0

```
const KeyKP0 enum:aego/input.Key
```

The KP0 key.

## KeyKP1

```
const KeyKP1 enum:aego/input.Key
```

The KP1 key.

## KeyKP2

```
const KeyKP2 enum:aego/input.Key
```

The KP2 key.

## KeyKP3

```
const KeyKP3 enum:aego/input.Key
```

The KP3 key.

## KeyKP4

```
const KeyKP4 enum:aego/input.Key
```

The KP4 key.

## KeyKP5

```
const KeyKP5 enum:aego/input.Key
```

The KP5 key.

## KeyKP6

```
const KeyKP6 enum:aego/input.Key
```

The KP6 key.

## KeyKP7

```
const KeyKP7 enum:aego/input.Key
```

The KP7 key.

## KeyKP8

```
const KeyKP8 enum:aego/input.Key
```

The KP8 key.

## KeyKP9

```
const KeyKP9 enum:aego/input.Key
```

The KP9 key.

## KeyKPEnter

```
const KeyKPEnter enum:aego/input.Key
```

The KPEnter key.

## KeyL

```
const KeyL enum:aego/input.Key
```

The L key.

## KeyLAlt

```
const KeyLAlt enum:aego/input.Key
```

The LAlt key.

## KeyLCtrl

```
const KeyLCtrl enum:aego/input.Key
```

The LCtrl key.

## KeyLeft

```
const KeyLeft enum:aego/input.Key
```

The Left key.

## KeyLGUI

```
const KeyLGUI enum:aego/input.Key
```

The LGUI key.

## KeyLShift

```
const KeyLShift enum:aego/input.Key
```

The LShift key.

## KeyM

```
const KeyM enum:aego/input.Key
```

The M key.

## KeyN

```
const KeyN enum:aego/input.Key
```

The N key.

## KeyNumLock

```
const KeyNumLock enum:aego/input.Key
```

The NumLock key.

## KeyO

```
const KeyO enum:aego/input.Key
```

The O key.

## KeyP

```
const KeyP enum:aego/input.Key
```

The P key.

## KeyPageDown

```
const KeyPageDown enum:aego/input.Key
```

The PageDown key.

## KeyPageUp

```
const KeyPageUp enum:aego/input.Key
```

The PageUp key.

## KeyPause

```
const KeyPause enum:aego/input.Key
```

The Pause key.

## KeyPressed

```
func KeyPressed(key aego/input.Key) bool
```

Reports whether a raw key went down this frame. For prototypes.

## KeyPrintScreen

```
const KeyPrintScreen enum:aego/input.Key
```

The PrintScreen key.

## KeyQ

```
const KeyQ enum:aego/input.Key
```

The Q key.

## KeyR

```
const KeyR enum:aego/input.Key
```

The R key.

## KeyRAlt

```
const KeyRAlt enum:aego/input.Key
```

The RAlt key.

## KeyRCtrl

```
const KeyRCtrl enum:aego/input.Key
```

The RCtrl key.

## KeyReleased

```
func KeyReleased(key aego/input.Key) bool
```

Reports whether a raw key went up this frame. For prototypes.

## KeyRGUI

```
const KeyRGUI enum:aego/input.Key
```

The RGUI key.

## KeyRight

```
const KeyRight enum:aego/input.Key
```

The Right key.

## KeyRShift

```
const KeyRShift enum:aego/input.Key
```

The RShift key.

## KeyS

```
const KeyS enum:aego/input.Key
```

The S key.

## KeyScrollLock

```
const KeyScrollLock enum:aego/input.Key
```

The ScrollLock key.

## KeySpace

```
const KeySpace enum:aego/input.Key
```

The Space key.

## KeyT

```
const KeyT enum:aego/input.Key
```

The T key.

## KeyTab

```
const KeyTab enum:aego/input.Key
```

The Tab key.

## KeyU

```
const KeyU enum:aego/input.Key
```

The U key.

## KeyUp

```
const KeyUp enum:aego/input.Key
```

The Up key.

## KeyV

```
const KeyV enum:aego/input.Key
```

The V key.

## KeyW

```
const KeyW enum:aego/input.Key
```

The W key.

## KeyX

```
const KeyX enum:aego/input.Key
```

The X key.

## KeyY

```
const KeyY enum:aego/input.Key
```

The Y key.

## KeyZ

```
const KeyZ enum:aego/input.Key
```

The Z key.

## MouseDown

```
func MouseDown(button aego/input.Button) bool
```

Reports whether a mouse button is held.

## MouseLeft

```
const MouseLeft enum:aego/input.Button
```

The Left mouse button.

## MouseMiddle

```
const MouseMiddle enum:aego/input.Button
```

The Middle mouse button.

## MousePos

```
func MousePos() Vec2
```

Returns the cursor in logical pixels of the game area.

## MousePressed

```
func MousePressed(button aego/input.Button) bool
```

Reports whether a mouse button went down this frame.

## MouseRight

```
const MouseRight enum:aego/input.Button
```

The Right mouse button.

## MouseWorld

```
func MouseWorld() Vec2
```

Returns the cursor in world units through the camera under it.

## MouseX1

```
const MouseX1 enum:aego/input.Button
```

The X1 mouse button.

## MouseX2

```
const MouseX2 enum:aego/input.Button
```

The X2 mouse button.

## Pointer

```
func Pointer() Vec2
```

Returns the cursor in logical pixels.

## PointerDelta

```
func PointerDelta() Vec2
```

Returns how far the cursor moved this frame.

## PopContext

```
func PopContext()
```

Removes the top input context.

## Pressed

```
func Pressed(action string) bool
```

Reports whether the action started. In Update it is true for one frame; in FixedUpdate for the first fixed step after the press.

## PressedP

```
func PressedP(player int, action string) bool
```

Is Pressed for one player.

## PushContext

```
func PushContext(context string)
```

Puts an input context on top of the stack.

## RebindConflict

```
func RebindConflict() string
```

Names the action that already used the new control, or explains why it was refused.

## Rebinding

```
func Rebinding() bool
```

Reports whether a rebind waits for input.

## Released

```
func Released(action string) bool
```

Reports whether the action ended this frame or fixed step.

## ReleasedP

```
func ReleasedP(player int, action string) bool
```

Is Released for one player.

## ResetBinding

```
func ResetBinding(action string)
```

Restores the project bindings of the action.

## ResetBindings

```
func ResetBindings()
```

Restores every project binding.

## SaveBindings

```
func SaveBindings()
```

Writes the player's settings profile now; changes are also saved on their own.

## SetContext

```
func SetContext(context string)
```

Replaces the whole stack with one context.
