aego/input
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.
On this page
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 in a desktop project. Resetting a script playground is not a reset of a physics world.
Example
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"))
}
}
}
}
Functions
| ActiveDevice | () int | Returns the device player 0 used last: -1 none, 0 keyboard and mouse, 1 to 4 a gamepad. |
| Axis | (action string) float | Returns the value of an axis action from -1 to 1, or the press strength of a button action. |
| Axis2 | (action string) Vec2 | Returns a 2D action as a vector no longer than 1; Y grows downward like the 2D world. |
| Axis2P | (player int, action string) Vec2 | Is Axis2 for one player. |
| AxisP | (player int, action string) float | Is Axis for one player. |
| 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 | (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. |
| Consume | (action string) | Clears the press and the buffer of the action, so later readers this frame do not see it. |
| DeviceChanged | () bool | Is true for the frame a gamepad was connected or removed. |
| Down | (key aego/input.Key) bool | Reports whether a raw key is held. For prototypes; release builds use actions. |
| Glyph | (action string) string | Returns the binding of the action for the active device as text, like [Space] or [A]. |
| Held | (action string) bool | Reports whether the action is active. |
| HeldP | (player int, action string) bool | Is Held for one player. |
| KeyPressed | (key aego/input.Key) bool | Reports whether a raw key went down this frame. For prototypes. |
| KeyReleased | (key aego/input.Key) bool | Reports whether a raw key went up this frame. For prototypes. |
| MouseDown | (button aego/input.Button) bool | Reports whether a mouse button is held. |
| MousePos | () Vec2 | Returns the cursor in logical pixels of the game area. |
| MousePressed | (button aego/input.Button) bool | Reports whether a mouse button went down this frame. |
| MouseWorld | () Vec2 | Returns the cursor in world units through the camera under it. |
| Pointer | () Vec2 | Returns the cursor in logical pixels. |
| PointerDelta | () Vec2 | Returns how far the cursor moved this frame. |
| PopContext | () | Removes the top input context. |
| 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 | (player int, action string) bool | Is Pressed for one player. |
| PushContext | (context string) | Puts an input context on top of the stack. |
| RebindConflict | () string | Names the action that already used the new control, or explains why it was refused. |
| Rebinding | () bool | Reports whether a rebind waits for input. |
| Released | (action string) bool | Reports whether the action ended this frame or fixed step. |
| ReleasedP | (player int, action string) bool | Is Released for one player. |
| ResetBinding | (action string) | Restores the project bindings of the action. |
| ResetBindings | () | Restores every project binding. |
| SaveBindings | () | Writes the player's settings profile now; changes are also saved on their own. |
| SetContext | (context string) | Replaces the whole stack with one context. |
94 constants and enum values are listed below.
ActiveDevice function
func ActiveDevice() int
Returns the device player 0 used last: -1 none, 0 keyboard and mouse, 1 to 4 a gamepad.
Example
onPad := input.ActiveDevice() > 0
Axis function
func Axis(action string) float
Returns the value of an axis action from -1 to 1, or the press strength of a button action.
Example
x := input.Axis("Move")
Axis2 function
func Axis2(action string) Vec2
Returns a 2D action as a vector no longer than 1; Y grows downward like the 2D world.
Example
v := input.Axis2("Move") * Speed
Axis2P function
func Axis2P(player int, action string) Vec2
Is Axis2 for one player.
Example
v := input.Axis2P(1, "Move")
AxisP function
func AxisP(player int, action string) float
Is Axis for one player.
Example
x := input.AxisP(1, "Move")
BeginRebind function
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.
Example
input.BeginRebind("Jump", 0)
Buffered function
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.
Example
if grounded && input.Buffered("Jump", 0) {
input.Consume("Jump")
}
Button enum
enum Button
Button is a mouse button.
Consume function
func Consume(action string)
Clears the press and the buffer of the action, so later readers this frame do not see it.
Example
input.Consume("Jump")
DeviceChanged function
func DeviceChanged() bool
Is true for the frame a gamepad was connected or removed.
Example
if input.DeviceChanged() {
Down function
func Down(key aego/input.Key) bool
Reports whether a raw key is held. For prototypes; release builds use actions.
Example
if input.Down(input.KeyShift) {
Glyph function
func Glyph(action string) string
Returns the binding of the action for the active device as text, like [Space] or [A].
Example
hint.Text = "Jump " + input.Glyph("Jump")
Held function
func Held(action string) bool
Reports whether the action is active.
Example
if input.Held("Run") {
HeldP function
func HeldP(player int, action string) bool
Is Held for one player.
Example
if input.HeldP(1, "Run") {
Key enum
enum Key
Key is a physical key, independent of the keyboard layout. Prefer actions; raw keys are for prototypes.
KeyA const
const KeyA enum:aego/input.Key
The A key.
KeyB const
const KeyB enum:aego/input.Key
The B key.
KeyBackspace const
const KeyBackspace enum:aego/input.Key
The Backspace key.
KeyC const
const KeyC enum:aego/input.Key
The C key.
KeyCapsLock const
const KeyCapsLock enum:aego/input.Key
The CapsLock key.
KeyD const
const KeyD enum:aego/input.Key
The D key.
KeyDelete const
const KeyDelete enum:aego/input.Key
The Delete key.
KeyDigit0 const
const KeyDigit0 enum:aego/input.Key
The Digit0 key.
KeyDigit1 const
const KeyDigit1 enum:aego/input.Key
The Digit1 key.
KeyDigit2 const
const KeyDigit2 enum:aego/input.Key
The Digit2 key.
KeyDigit3 const
const KeyDigit3 enum:aego/input.Key
The Digit3 key.
KeyDigit4 const
const KeyDigit4 enum:aego/input.Key
The Digit4 key.
KeyDigit5 const
const KeyDigit5 enum:aego/input.Key
The Digit5 key.
KeyDigit6 const
const KeyDigit6 enum:aego/input.Key
The Digit6 key.
KeyDigit7 const
const KeyDigit7 enum:aego/input.Key
The Digit7 key.
KeyDigit8 const
const KeyDigit8 enum:aego/input.Key
The Digit8 key.
KeyDigit9 const
const KeyDigit9 enum:aego/input.Key
The Digit9 key.
KeyDown const
const KeyDown enum:aego/input.Key
The Down key.
KeyE const
const KeyE enum:aego/input.Key
The E key.
KeyEnd const
const KeyEnd enum:aego/input.Key
The End key.
KeyEnter const
const KeyEnter enum:aego/input.Key
The Enter key.
KeyEscape const
const KeyEscape enum:aego/input.Key
The Escape key.
KeyF const
const KeyF enum:aego/input.Key
The F key.
KeyF1 const
const KeyF1 enum:aego/input.Key
The F1 key.
KeyF10 const
const KeyF10 enum:aego/input.Key
The F10 key.
KeyF11 const
const KeyF11 enum:aego/input.Key
The F11 key.
KeyF12 const
const KeyF12 enum:aego/input.Key
The F12 key.
KeyF2 const
const KeyF2 enum:aego/input.Key
The F2 key.
KeyF3 const
const KeyF3 enum:aego/input.Key
The F3 key.
KeyF4 const
const KeyF4 enum:aego/input.Key
The F4 key.
KeyF5 const
const KeyF5 enum:aego/input.Key
The F5 key.
KeyF6 const
const KeyF6 enum:aego/input.Key
The F6 key.
KeyF7 const
const KeyF7 enum:aego/input.Key
The F7 key.
KeyF8 const
const KeyF8 enum:aego/input.Key
The F8 key.
KeyF9 const
const KeyF9 enum:aego/input.Key
The F9 key.
KeyG const
const KeyG enum:aego/input.Key
The G key.
KeyH const
const KeyH enum:aego/input.Key
The H key.
KeyHome const
const KeyHome enum:aego/input.Key
The Home key.
KeyI const
const KeyI enum:aego/input.Key
The I key.
KeyInsert const
const KeyInsert enum:aego/input.Key
The Insert key.
KeyJ const
const KeyJ enum:aego/input.Key
The J key.
KeyK const
const KeyK enum:aego/input.Key
The K key.
KeyKP0 const
const KeyKP0 enum:aego/input.Key
The KP0 key.
KeyKP1 const
const KeyKP1 enum:aego/input.Key
The KP1 key.
KeyKP2 const
const KeyKP2 enum:aego/input.Key
The KP2 key.
KeyKP3 const
const KeyKP3 enum:aego/input.Key
The KP3 key.
KeyKP4 const
const KeyKP4 enum:aego/input.Key
The KP4 key.
KeyKP5 const
const KeyKP5 enum:aego/input.Key
The KP5 key.
KeyKP6 const
const KeyKP6 enum:aego/input.Key
The KP6 key.
KeyKP7 const
const KeyKP7 enum:aego/input.Key
The KP7 key.
KeyKP8 const
const KeyKP8 enum:aego/input.Key
The KP8 key.
KeyKP9 const
const KeyKP9 enum:aego/input.Key
The KP9 key.
KeyKPEnter const
const KeyKPEnter enum:aego/input.Key
The KPEnter key.
KeyL const
const KeyL enum:aego/input.Key
The L key.
KeyLAlt const
const KeyLAlt enum:aego/input.Key
The LAlt key.
KeyLCtrl const
const KeyLCtrl enum:aego/input.Key
The LCtrl key.
KeyLeft const
const KeyLeft enum:aego/input.Key
The Left key.
KeyLGUI const
const KeyLGUI enum:aego/input.Key
The LGUI key.
KeyLShift const
const KeyLShift enum:aego/input.Key
The LShift key.
KeyM const
const KeyM enum:aego/input.Key
The M key.
KeyN const
const KeyN enum:aego/input.Key
The N key.
KeyNumLock const
const KeyNumLock enum:aego/input.Key
The NumLock key.
KeyO const
const KeyO enum:aego/input.Key
The O key.
KeyP const
const KeyP enum:aego/input.Key
The P key.
KeyPageDown const
const KeyPageDown enum:aego/input.Key
The PageDown key.
KeyPageUp const
const KeyPageUp enum:aego/input.Key
The PageUp key.
KeyPause const
const KeyPause enum:aego/input.Key
The Pause key.
KeyPressed function
func KeyPressed(key aego/input.Key) bool
Reports whether a raw key went down this frame. For prototypes.
Example
if input.KeyPressed(input.KeyF5) {
KeyPrintScreen const
const KeyPrintScreen enum:aego/input.Key
The PrintScreen key.
KeyQ const
const KeyQ enum:aego/input.Key
The Q key.
KeyR const
const KeyR enum:aego/input.Key
The R key.
KeyRAlt const
const KeyRAlt enum:aego/input.Key
The RAlt key.
KeyRCtrl const
const KeyRCtrl enum:aego/input.Key
The RCtrl key.
KeyReleased function
func KeyReleased(key aego/input.Key) bool
Reports whether a raw key went up this frame. For prototypes.
Example
if input.KeyReleased(input.KeySpace) {
KeyRGUI const
const KeyRGUI enum:aego/input.Key
The RGUI key.
KeyRight const
const KeyRight enum:aego/input.Key
The Right key.
KeyRShift const
const KeyRShift enum:aego/input.Key
The RShift key.
KeyS const
const KeyS enum:aego/input.Key
The S key.
KeyScrollLock const
const KeyScrollLock enum:aego/input.Key
The ScrollLock key.
KeySpace const
const KeySpace enum:aego/input.Key
The Space key.
KeyT const
const KeyT enum:aego/input.Key
The T key.
KeyTab const
const KeyTab enum:aego/input.Key
The Tab key.
KeyU const
const KeyU enum:aego/input.Key
The U key.
KeyUp const
const KeyUp enum:aego/input.Key
The Up key.
KeyV const
const KeyV enum:aego/input.Key
The V key.
KeyW const
const KeyW enum:aego/input.Key
The W key.
KeyX const
const KeyX enum:aego/input.Key
The X key.
KeyY const
const KeyY enum:aego/input.Key
The Y key.
KeyZ const
const KeyZ enum:aego/input.Key
The Z key.
MouseDown function
func MouseDown(button aego/input.Button) bool
Reports whether a mouse button is held.
Example
if input.MouseDown(input.MouseLeft) {
MouseLeft const
const MouseLeft enum:aego/input.Button
The Left mouse button.
MouseMiddle const
const MouseMiddle enum:aego/input.Button
The Middle mouse button.
MousePos function
func MousePos() Vec2
Returns the cursor in logical pixels of the game area.
Example
p := input.MousePos()
MousePressed function
func MousePressed(button aego/input.Button) bool
Reports whether a mouse button went down this frame.
Example
if input.MousePressed(input.MouseRight) {
MouseRight const
const MouseRight enum:aego/input.Button
The Right mouse button.
MouseWorld function
func MouseWorld() Vec2
Returns the cursor in world units through the camera under it.
Example
target := input.MouseWorld()
MouseX1 const
const MouseX1 enum:aego/input.Button
The X1 mouse button.
MouseX2 const
const MouseX2 enum:aego/input.Button
The X2 mouse button.
Pointer function
func Pointer() Vec2
Returns the cursor in logical pixels.
Example
p := input.Pointer()
PointerDelta function
func PointerDelta() Vec2
Returns how far the cursor moved this frame.
Example
look += input.PointerDelta()
PopContext function
func PopContext()
Removes the top input context.
Example
input.PopContext()
Pressed function
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.
Example
if input.Pressed("Attack") {
PressedP function
func PressedP(player int, action string) bool
Is Pressed for one player.
Example
if input.PressedP(1, "Jump") {
PushContext function
func PushContext(context string)
Puts an input context on top of the stack.
Example
input.PushContext("Menu")
RebindConflict function
func RebindConflict() string
Names the action that already used the new control, or explains why it was refused.
Example
if input.RebindConflict() != "" {
Rebinding function
func Rebinding() bool
Reports whether a rebind waits for input.
Example
if input.Rebinding() {
Released function
func Released(action string) bool
Reports whether the action ended this frame or fixed step.
Example
if input.Released("Jump") {
ReleasedP function
func ReleasedP(player int, action string) bool
Is Released for one player.
Example
if input.ReleasedP(1, "Jump") {
ResetBinding function
func ResetBinding(action string)
Restores the project bindings of the action.
Example
input.ResetBinding("Jump")
ResetBindings function
func ResetBindings()
Restores every project binding.
Example
input.ResetBindings()
SaveBindings function
func SaveBindings()
Writes the player's settings profile now; changes are also saved on their own.
Example
input.SaveBindings()
SetContext function
func SetContext(context string)
Replaces the whole stack with one context.
Example
input.SetContext("Gameplay")