input

(module)

Module for accessing input devices such as touches, keyboard, mouse and gamepads

Touches

class touch

Represents a single touch over time. Generated in response to touch events by the device in response to user interactions

id: number

An id that can be used to uniquely identify the touch

state: enum

The current state of the touch, can be:

  • BEGAN - the touch began this frame

  • MOVING - the touch moved this frame

  • ENDED - the touch ended this frame

  • CANCELLED - the touch was cancelled (usually by another view or gesture recognizer)

type: enum

The type of touch, can be:

  • touch.direct - a touch resulting from direct contact with the screen

  • touch.indirect - a touch that does not result from direct contact with the screen

  • touch.pencil - a touch resulting from the pencil

  • touch.pointer - a touch resulting from a button based device

x: number

The x position of the touch (in screen coordinates)

y: number

The y position of the touch (in screen coordinates)

prevX: number

The previous x position of the touch (in screen coordinates)

prevY: number

The previous y position of the touch (in screen coordinates)

deltaX: number

The x position delta of the touch (in screen coordinates)

deltaY: number

The y position delta of the touch (in screen coordinates)

pos: vec2

The position of the touch (in screen coordinates) as a vector

prevPos: vec2

The previous position of the touch (in screen coordinates) as a vector

delta: number

The position delta of the touch (in screen coordinates) as a vector

force: number

The amount of force being applied (only applies to pencil type touches)

maxForce: number

The maximum amount of force that can be applied (only applies to pencil type touches)

timestamp: number

The time when this touch event occured (only applies to pencil type touches)

azimuth: number

The azimuth angle of the pencil (only applies to pencil type touches)

altitude: number

The altitude angle of the pencil

radiusTolerance: number

The amount the estimated radius can vary due to hardware tolerances

radius: number

The estimated radius of the touch

precisePos: vec2

The precise location of the touch (if available)

precisePrevPos: vec2

The previous precise location of the touch (if available)

Gestures

class gesture

Represents a single gesture event

state: enum

The current state of the gesture

location: vec2

The location of the gesture event on the screen

translation: vec2

The translation of the gesture event relative to its starting location

delta: vec2

The delta of the gesture event since last update

pinchScale: number

The scale of a pinch gesture relative to its starting distance

pinchDelta: number

The delta of the pinch distance since last update

pinchVelocity: number

The current change in pinch distance over time

rotationAngle: number

The current angle of a rotation gesture relative to its’ starting angle

rotationVelocity: number

The current change in rotation angle over time

touchCount: integer

The current number of touches associated with this gesture

class gesture.tap

Tap gesture recognizer (using system gesture recognizer for implementation)

static gesture.tap(callback[, minTouches = 1, maxTouches = 1])

Creates and registers a new tap gesture recognizer that will call callback(gesture) when recognized

enabled: boolean

Enables/disables this gesture recognizer

class gesture.pan

Pan gesture recognizer (using system gesture recognizer for implementation)

static gesture.pan(callback[, minTouches = 1, maxTouches = 1])

Creates and registers a new pan gesture recognizer that will call callback(gesture) when recognized

enabled: boolean

Enables/disables this gesture recognizer

class gesture.pinch

Pinch gesture recognizer (using system gesture recognizer for implementation)

static gesture.pinch(callback)

Creates and registers a new pinch gesture recognizer that will call callback(gesture) when recognized

enabled: boolean

Enables/disables this gesture recognizer

class gesture.rotation

Rotation gesture recognizer (using system gesture recognizer for implementation)

static gesture.rotation(callback)

Creates and registers a new rotation gesture recognizer that will call callback(gesture) when recognized

enabled: boolean

Enables/disables this gesture recognizer

Keyboard

key.pressing(keyCode)

Queries whether the key is currently being pressed this frame

Parameters:

keyCode (constant) – The keyCode to query

Returns:

Is the key being pressed this frame

Return type:

boolean

key.wasPressed(keyCode)

Queries whether the key is was pressed down this frame

Parameters:

keyCode (constant) – The keyCode to query

Returns:

Was the key pressed down this frame

Return type:

boolean

key.wasReleased(keyCode)

Queries whether the supplied key code was released this frame

Parameters:

keyCode (constant) – The keyCode to query

Returns:

Was the key released this frame

Return type:

boolean

key.modifiers()

Queries the current key modifiers as a bit field, which is composed of the following bit mask constants:

Parameters:

keyCode (constant) – The keyCode to query

Returns:

Was the key released this frame

Return type:

boolean

Constants - Key Codes

leftAlt: const
rightAlt: const
alt: const
leftCtrl: const
rightCtrl: const
ctrl: const
leftCmd: const
rightCmd: const
cmd: const
esc: const
return: const
tab: const
space: const
backspace: const
up: const
down: const
left: const
right: const
insert: const
delete: const
home: const
end: const
pageup: const
pagedown: const
print: const
plus: const
minus: const
leftbracket: const
rightbracket: const
semicolon: const
quote: const
comma: const
period: const
slash: const
backslash: const
tilde: const
f1: const
f2: const
f3: const
f4: const
f5: const
f6: const
f7: const
f8: const
f9: const
f10: const
f11: const
f12: const
numpad0: const
numpad1: const
numpad2: const
numpad3: const
numpad4: const
numpad5: const
numpad6: const
numpad7: const
numpad8: const
numpad9: const
num0: const
num1: const
num2: const
num3: const
num4: const
num5: const
num6: const
num7: const
num8: const
num9: const
a: const
b: const
c: const
d: const
e: const
f: const
g: const
h: const
i: const
j: const
k: const
l: const
m: const
n: const
o: const
p: const
q: const
r: const
s: const
t: const
u: const
v: const
w: const
x: const
y: const
z: const

Gamepad

class gamepad
all: table<gamepad>

A list of all currently connected gamepads

current: gamepad

The current main active gamepad (or nil if none connected)

virtual: gamepad.virtualGamepad

Gets or creates a virtual gamepad which will substitute on-screen controls if no controller is currently connected

connected: function(gamepad)

Callback for when a gamepad is connected

disconnected: function(gamepad)

Callback for when a gamepad is disconnected

leftShoulder: gamepad.button

The left shoulder button

rightShoulder: gamepad.button

The right shoulder button

leftTrigger: gamepad.button

The left trigger

rightTrigger: gamepad.button

The right trigger

dpad: gamepad.directionalPad
leftStick: gamepad.directionalPad
rightStick: gamepad.directionalPad
leftStickButton: gamepad.button
rightStickButton: gamepad.button
buttonA: gamepad.button
buttonB: gamepad.button
buttonX: gamepad.button
buttonY: gamepad.button
home: gamepad.button
menu: gamepad.button
options: gamepad.button
touchpadButton: gamepad.button
touchpadSurface: gamepad.directionalPad
touchpadSurface: gamepad.directionalPad
batteryLevel: number
batteryState: const
light: color
class button
pressing: boolean
pressed: boolean
released: boolean
value: number
touching: boolean
class directionalPad
pressing: boolean
dir: vec2
x: number
y: number
left: boolean
right: boolean
up: boolean
down: boolean