The comfortable framework for making games in Wren
The input module allows you to retrieve the state of input devices such as the keyboard, mouse and game controllers.
It contains the following classes:
An instance of DigitalInput represents an input such as a keyboard key, mouse button or controller button, which can be either “pressed” or “unpressed”.
repeat(): VoidCauses the current state of the input to be repeated, which can affect the justPressed property. This is useful in certain scenarios where an input’s state may be tested repeatedly, but before the user has had a chance to release the input.
reset(): VoidResets the input state, as if the input was just set to no longer be down. This is useful in certain scenarios where an input’s state may be tested repeatedly, but before the user has had a chance to release the input.
static down: BooleanThis is true if the digital input is “pressed” or otherwise engaged.
static justPressed: BooleanReturns true if the input was “pressed” down on this tick.
static previous: BooleanThis gives you the value of “down” on the previous tick, since input was last processed. (Depending on game loop lag, input may be processed once for multiple update ticks.)
static repeats: NumberThis counts the number of ticks that an input has been engaged for. If the input isn’t engaged, this should be zero.
This class gives easy access to your operating system’s clipboard for copy/paste operations.
static content: StringReturns the current content of the clipboard. Set this field to put a new value into the user’s clipboard.
You can use an InputGroup to check the state of multiple DigitalInput objects simultanously. It also includes some features for checking if the input is being held.
This is useful for implementing more complex control schemes where input/key remapping is required.
new(inputs: DigitalInput | Sequence<DigitalInput>): InputGroupGiven either a single input, or a sequence of multiple inputs, it creates an InputGroup object.
repeating: BooleanWhen set to true, this input is allowed to fire repeatedly.
frequency: NumberThe number of ticks an input needs to be held for before the group considers it a repeat.
threshold: NumberThe InputGroup won’t start checking for repeats until after threshold ticks have occurred.
down: BooleanReturns true if any of the group inputs are down.
justPressed: BooleanReturns true if any of the group inputs are justPressed.
firing: BooleanReturns true when an input has just ben pressed. If repeating is set and the input has been
held down longer than threshold ticks, then firing will be true every frequency ticks.
reset(): VoidResets the input state for the entire group, as if the input was just set to no longer be down. This is useful in certain scenarios where an input’s state may be tested repeatedly, but before the user has had a chance to release the input.
static allPressed: Map<string, DigitalInput>This returns a map containing the key names and corresponding DigitalInput objects, for all keys which are currently “down”.
static compositionText: StringWhen handleText is true, this method returns the text of the currently selected composition received from the user’s IME, if they are using one. Otherwise, this value is null.
static compositionRange: RangeWhen handleText is true, this provides a range object indicating which portion of the compositionText is being modified by the IME.
static handleText: BooleanIndicates whether the text input features of DOME are enabled or not.
static text: StringWhen handleText is true, this method returns text entered since the previous tick. You should store this value if you need it to persist across ticks.
static [name]: DigitalInputThis returns a digital input of a valid name. See Keyboard.isKeyDown for a list of valid names.
It contains the following classes:
An instance of DigitalInput represents an input such as a keyboard key, mouse button or controller button, which can be either “pressed” or “unpressed”.
repeat(): VoidCauses the current state of the input to be repeated, which can affect the justPressed property. This is useful in certain scenarios where an input’s state may be tested repeatedly, but before the user has had a chance to release the input.
reset(): VoidResets the input state, as if the input was just set to no longer be down. This is useful in certain scenarios where an input’s state may be tested repeatedly, but before the user has had a chance to release the input.
static down: BooleanThis is true if the digital input is “pressed” or otherwise engaged.
static justPressed: BooleanReturns true if the input was “pressed” down on this tick.
static previous: BooleanThis gives you the value of “down” on the previous tick, since input was last processed. (Depending on game loop lag, input may be processed once for multiple update ticks.)
static repeats: NumberThis counts the number of ticks that an input has been engaged for. If the input isn’t engaged, this should be zero.
This class gives easy access to your operating system’s clipboard for copy/paste operations.
static content: StringReturns the current content of the clipboard. Set this field to put a new value into the user’s clipboard.
You can use an InputGroup to check the state of multiple DigitalInput objects simultanously. It also includes some features for checking if the input is being held.
This is useful for implementing more complex control schemes where input/key remapping is required.
static allPressed: Map<string, DigitalInput>This returns a map containing the key names and corresponding DigitalInput objects, for all keys which are currently “down”.
static compositionText: StringWhen handleText is true, this method returns the text of the currently selected composition received from the user’s IME, if they are using one. Otherwise, this value is null.
static compositionRange: RangeWhen handleText is true, this provides a range object indicating which portion of the compositionText is being modified by the IME.
static handleText: BooleanIndicates whether the text input features of DOME are enabled or not.
static text: StringWhen handleText is true, this method returns text entered since the previous tick. You should store this value if you need it to persist across ticks.
static [name]: DigitalInputThis returns a digital input of a valid name. See Keyboard.isKeyDown for a list of valid names.
static isButtonPressed(key: String): Booleanstatic isKeyDown(key: String): BooleanReturns true if the named key is pressed. The key uses the SDL key name, which can be referenced here.
textRegion(x: Number, y: Number, width: Number, height: Number): voidUse this to hint to the OS at where the user is expecting entered text to be displayed. The OS may use this to display the IME in a suitable location.
This must be set while handleText is true, or the effect may be inconsistent.
static cursor: StringGets or sets the system cursor to the name provided. Available cursor names are:
arrowibeamwaitcrosshairwaitarrowsizenwsesizeneswsizewesizenssizeallnohandMac OS X will set the system cursor to arrow if wait or waitarrow is set.
Mac OS X will set the system cursor to a closed hand if sizenwse, sizenesw or sizeall is set.
static hidden: BooleanControls whether the mouse cursor is shown or hidden. You can set and read from this field.
static pos: Vectorstatic position: VectorReturns a vector of (Mouse.x, Mouse.y) for convenience.
static relative: BooleanIf set to true, the mouse is placed into relative mode. In this mode, the mouse will be fixed to the center of the screen. You can set and read from this field. This changes the behaviour of the x and y fields.
static scroll: VectorReturns a vector of (scrollX, scrollY), for convenience.
static scrollX: NumberThe total distance the mouse wheel has scrolled horizontally in the past tick. Left is negative and right is positive.
static scrollY: NumberThe total distance the mouse wheel has scrolled vertically in the past tick. Left is negative and down is positive.
static x: NumberThe x position relative to the Canvas. This accounts for the window being resized and the viewport moving. If Mouse.relative is set, this will be the relative change of the mouse x position since the previous tick.
static y: NumberThe y position relative to the Canvas. This accounts for the window being resized and the viewport moving. If Mouse.relative is set, this will be the relative change of the mouse y position since the previous tick.
static [name]: DigitalInputThis returns a digital input of a valid name. See Mouse.isButtonPressed for a list of valid names.
static isButtonPressed(name: String/Number): BooleanReturns true if the named mouse button is pressed. You can use an index from 1-5 (button 0 is invalid) or a lowercase name:
leftmiddlerightx1x2You can use a game pad as input for your games. DOME expects a game pad similar to those used by popular games consoles, with a D-Pad, face buttons, triggers and analog sticks.
all: List<GamePad>Returns a list of GamePad objects representing all attached gamepads.
next: GamePadReturns a GamePad representing an arbitrary attached gamepad. This isn’t guarenteed to return the same object every time, so you should cache it.
[id]: GamePadThis will return an object representing a GamePad. You can then read the state of that gamepad using the instance methods below.
If no gamepads are attached, you will receive a “dummy” object which will report null or empty values.
allPressed: Map<string, DigitalInput>This returns a map containing the key names and corresponding DigitalInput objects, for all keys which are currently “down”.
attached: BooleanThis returns true if the gamepad is still attached to the system.
id: NumberReturns the instance id for this gamepad, which can be used to fetch it using GamePad[id].
name: StringIf the gamepad is attached, this returns the SDL internal name for that device.
[name]: DigitalInputThis returns a digital input of a valid name. See GamePad.isButtonPressed for a list of valid names.
isButtonPressed(button: String): BooleanReturns true if the named button is pressed. Valid button names are:
left - D-Pad Leftright - D-Pad Rightup - D-Pad Updown - D-Pad DownA - A ButtonB - B ButtonX - X ButtonY - Y Buttonback - Back Button (Often referred to as “Select”)start - Start Buttonguide - Guide Button (On an XBox controller, this is the XBox button)leftstick - Clicking the left stickrightstick - Clicking the right stickleftshoulder - Left shoulder buttonrightshoulder - Right shoulder buttonThese button names are case insensitive.
getTrigger(side: String): NumberGets the current state of the trigger on the specified side, as a number between 0.0 and 1.0.
Valid sides are left and right.
getAnalogStick(side: String): VectorGets the current state of the specified analog stick as a Vector, with x and y values, which are normalised as values between -1.0 and 1.0.
Valid sides are left and right.
rumble(strength: Number, duration: Number): VoidIf the gamepad is able to vibrate, it will vibrate with a strength, clamped between 0.0 and 1.0, for a duration of milliseconds. Rumble and haptic feedback is dependant on platform drivers.