keyPressed
Canonical ID: events.keyPressed. Nederlands: toetsGedrukt.
Runs on a released-to-pressed key transition. Operating-system auto-repeat does not create more invocations until key-up. The host must expose keyboard events; the program stays active while these handlers are registered. A polling call answers current state instead, so use keyDown for continuous movement and this event for single actions.
Signature
when keyPressed("key"):
Arguments
| Parameter | Type | Requirement |
|---|---|---|
key |
Text literal | Direct nonempty key name, for example “space”, “left”, or “a”. |
Return value
Event descriptor.
Example
# language: en
when started():
clearCanvas("white")
when keyPressed("space"):
circle(320, 180, 30, "blue")
when keyPressed("escape"):
exitApp()
Use an IDE/browser/native graphical host. Space draws a circle; Escape exits on hosts exposing that key.
Notes and common mistakes
Use the function name for your source language. Its canonical ID is a shared documentation label; you do not type that ID as a call. Giving your own variable or function the same name can hide the built-in. Supply the documented arguments and value types. Pliro reports mismatches when checking can detect them, or when the call runs.
An event descriptor selects the event in a top-level when header, outside other blocks (E3201–E3203). A reporter is an ordinary function that returns a value, such as pointerX; broadcast is an ordinary call too. A handler is the block reacting to an event. Key and pointer handlers keep a run ready for future input and need host support (E4019). Pointer reporters need the current pointer event (E4020). The whole run has a shared event-work limit (E4018). Ordinary setup must finish before handlers get turns. See event rules and pointer positions.
Related entries
started · after · messageReceived · pointerPressed · pointerReleased · Programming guides · Host support · Calls and arguments
