.onKeyDown()

Description

onKeyDown checks if a specific key was just pressed (triggered once when the key is first pressed). Returns true only on the first frame the key is pressed, unlike isKeyDown which returns true for the entire duration the key is held.

Parameters

onKeyDown takes no parameters.

Usage On Strings

if "A".onKeyDown() (
  log "A key was just pressed"
)

if "Enter".onKeyDown() (
  log "Enter was just pressed"
  // Good for triggering one-time actions
)

// Example of the difference between onKeyDown and isKeyDown
loop 100 (
  if "Space".isKeyDown() (
    log "Space is being held"  // Prints every frame while space is held
  )
  if "Space".onKeyDown() (
    log "Space was just pressed"  // Prints only once when space is first pressed
  )
)

// Uses the same key names as isKeyDown():
// - Letters: "A" through "Z"
// - Numbers: "0" through "9"
// - Special keys: "Space", "Enter", "Tab", "Shift", "Control", "Alt"
// - Arrow keys: "Up_Arrow", "Down_Arrow", "Left_Arrow", "Right_Arrow"
// - Function keys: "F1" through "F12"

Last updated

Was this helpful?