RUSTICDOCSSearch documentation

rustic.key()

Input

Compatibility

Supported languages: C, C++, C#, Python, JavaScript, Lua 5.4, Luau, Java, PHP and HTML/inline JavaScript (binding spellings and return shapes differ).

Use a compatible native engine build and the language tools required by your binding. This does not establish browser/mobile export or release qualification for every OS.

The signature below is the shared reference notation; language examples show the actual binding syntax. Question marks mark optional arguments and explicit defaults are shown where recorded. Do not copy reference notation as a typed declaration.

See Feature status and compatibility for API 1.0/1.1 and per-method restrictions. Engine release tags and Docs v0.1 are independent versions.

Signature

rustic.key(key)

Setup and usage

Read rustic.key(name).held in FixedUpdate for movement. Query keyboard edges, mouse clicks and wheel deltas in Update. Use Input touch and object click subscriptions in Start.

Parameters

VariableTypeRequiredDescription
keystringYesA physical key name such as KeyW, Space, or ArrowUp.

Return and timing

Key reads return { pressed, released, held, axis }. Packaged desktop games also report press and release edges and ordered key events. Input.mouseButton() returns {pressed, released, held, clicked}. Input.mouseWheel() returns signed {x, y} scroll deltas in line units. Positive x means right and positive y means up. Input.touches() and Input.touchEvents() return contact/event arrays; Input.clicks() returns {entity, pointer, point} records. Input subscriptions return disconnectable Events connections and callbacks receive (id, [x,y,0], device, pressure).

Execution behavior

Core write timing differs between immediate Lua host calls, deferred JavaScript/Web commands and external SDK query flushes. Scheduled actions advance with the scene clock; synchronous queries evaluate at the call. Follow execution rules and the return/timing notes for this category.

Language examples

Use these snippets inside Start/on_start after generating the Programming Workspace and attaching the script. Python imports rustic, Game and instance from rustic; C++ includes rustic.hpp; C includes rustic.h; C# uses using static Rustic; Java runs inside a Rustic subclass; PHP declares global $rustic, $Game, $instance in its callback. HTML uses an inline script in a ui/ asset. See Lifecycle callbacks for complete registration examples. Public-property examples require a declared integer health property. Scene examples require the named objects to exist before Play.

Lua 5.4

lua
if rustic.key('KeyW').held then
  print('forward key is held')
end
local touches = Input.touches()
local action = rustic.input("Jump")
local events = rustic.key_events()
local anyPressed = rustic.any_key_pressed()

Shared Input constraints

  • For multi-touch contacts and CanTouch-gated object click subscriptions, see Touchscreen input and object clicks, including setup, callbacks and native binding signatures. Read pointer snapshots in Update. The embedded Play viewport forwards held KeyW, KeyA, KeyS, KeyD, ArrowUp, ArrowDown, ArrowLeft, ArrowRight, ShiftLeft, and ShiftRight. Mouse button and wheel queries work in embedded Play and packaged desktop games. Start a click over the game image and release inside it. Focus the packaged game window for keyboard input. Editor-launched New Window has no keyboard or mouse bridge. Follow the Lua controller guide for attachment steps, a complete example, and troubleshooting.
  • Every gameplay language calls the engine-owned API. Rustic supplies SDKs and dispatches callbacks; scripts do not parse requests or serialize responses. See the language guide for complete setup and callback registration.

Errors and debugging

Read the constraints above and the Console diagnostic. Invalid types, non-finite values, stale targets or unavailable native services can fail validation. A failed callback disables the behavior; a failed source reload keeps the last good instance. Exact error messages depend on the language adapter. See Troubleshooting.

All input APIs