Skip to content

Custom Input

Stonescript can read player input through the ?key game state. This enables advanced behaviours — different AI modes, custom mini-games, or entirely new interactive experiences layered on top of Stone Story.

Basic usage

// Print the current input state every frame
>@key@

Key code variants

Each action has three variants:

VariantWhen true
leftKey is held down
leftBeginKey was just pressed (first frame only)
leftEndKey was just released (first frame only)

Full key code table

HeldPressedReleasedDefault PC keys
leftleftBeginleftEndA or ←
rightrightBeginrightEndD or →
upupBeginupEndW or ↑
downdownBegindownEndS or ↓
primaryprimaryBeginprimaryEndLMB, Return
backbackBeginbackEndX
ability1ability1Beginability1EndShift
ability2ability2Beginability2EndControl
bumpLbumpLBeginbumpLEndZ
bumpRbumpRBeginbumpREndC

Example — Rogue-like movement

Move an @ symbol across the screen like a classic Rogue-like character. The Begin variants ensure movement only steps once per key press:

var x = 0
var y = 0

?key = leftBegin
  x--
?x < 0
  x = 0

?key = rightBegin
  x++

?key = upBegin
  y--
?y < 0
  y = 0

?key = downBegin
  y++

>`@x@,@y@,#ffffff,@

Rebinding keys

Keys can be rebound at runtime using the key namespace. This lets scripts reassign any action to any key:

?loc.begin
  key.Bind("Potion", "P")
// Now P activates the potion instead of pausing

See also

Stonescript is part of Stone Story RPG.