# .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

```javascript
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"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://osl.mistium.com/methods/keyboard/.onkeydown.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
