Input manager. Used to recieve input from keyboard and mouse.
To access the Input manager use Shaku.input
.
Kind: global class
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Number
String
Vector2
Boolean
Boolean
Boolean
Vector2
Vector2
Vector2
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Number
Number
Gamepad
Array.<String>
Boolean
Boolean
Boolean
Boolean
boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Number
Number
Boolean
Boolean
Create the manager.
Boolean
If true, will prevent default input events by calling preventDefault().
Kind: instance property of Input
Boolean
By default, when holding wheel button down browsers will turn into special page scroll mode and will not emit mouse move events. if this property is set to true (default), the Input manager will prevent this behavior, so we could still get mouse delta while mouse wheel is held down.
Kind: instance property of Input
Boolean
If true (default), will disable the context menu (what typically opens when you right click the page).
Kind: instance property of Input
Boolean
If true (default), will treat touch events (touch start / touch end / touch move) as if the user clicked and moved a mouse.
Kind: instance property of Input
Boolean
If true (default), will delegate events from mapped gamepads to custom keys. This will add the following codes to all basic query methods (down, pressed, released, doublePressed, doubleReleased):
gamepad
is the gamepad index: gamepad0, gamepad1, gamepad2..Kind: instance property of Input
Boolean
If true (default), will reset all states if the window loses focus.
Kind: instance property of Input
Number
Default time, in milliseconds, to consider two consecutive key presses as a double-press.
Kind: instance property of Input
Get the Mouse Buttons enum.
Kind: instance property of Input
See: MouseButtons
Get the Keyboard Buttons enum.
Kind: instance property of Input
See: KeyboardKeys
String
Return the string code to use in order to get touch events.
Kind: instance property of Input
Returns: String
- Key code to use for touch events.
Vector2
Get touch screen touching position. Note: if not currently touching, will return last known position.
Kind: instance property of Input
Returns: Vector2
- Touch position.
Boolean
Get if currently touching a touch screen.
Kind: instance property of Input
Returns: Boolean
- True if currently touching the screen.
Boolean
Get if started touching a touch screen in current frame.
Kind: instance property of Input
Returns: Boolean
- True if started touching the screen now.
Boolean
Get if stopped touching a touch screen in current frame.
Kind: instance property of Input
Returns: Boolean
- True if stopped touching the screen now.
Vector2
Get mouse position.
Kind: instance property of Input
Returns: Vector2
- Mouse position.
Vector2
Get mouse previous position (before the last endFrame() call).
Kind: instance property of Input
Returns: Vector2
- Mouse position in previous frame.
Vector2
Get mouse movement since last endFrame() call.
Kind: instance property of Input
Returns: Vector2
- Mouse change since last frame.
Boolean
Get if mouse is currently moving.
Kind: instance property of Input
Returns: Boolean
- True if mouse moved since last frame, false otherwise.
Boolean
Get if any of the shift keys are currently down.
Kind: instance property of Input
Returns: Boolean
- True if there’s a shift key pressed down.
Boolean
Get if any of the Ctrl keys are currently down.
Kind: instance property of Input
Returns: Boolean
- True if there’s a Ctrl key pressed down.
Boolean
Get if any of the Alt keys are currently down.
Kind: instance property of Input
Returns: Boolean
- True if there’s an Alt key pressed down.
Boolean
Get if any keyboard key was pressed this frame.
Kind: instance property of Input
Returns: Boolean
- True if any key was pressed down this frame.
Boolean
Get if any keyboard key is currently down.
Kind: instance property of Input
Returns: Boolean
- True if there’s a key pressed down.
Boolean
Get if any mouse button was pressed this frame.
Kind: instance property of Input
Returns: Boolean
- True if any of the mouse buttons were pressed this frame.
Boolean
Get if any mouse button is down.
Kind: instance property of Input
Returns: Boolean
- True if any of the mouse buttons are pressed.
Number
Get mouse wheel sign.
Kind: instance property of Input
Returns: Number
- Mouse wheel sign (-1 or 1) for wheel scrolling that happened during this frame.
Will return 0 if mouse wheel is not currently being used.
Number
Get mouse wheel value.
Kind: instance property of Input
Returns: Number
- Mouse wheel value.
Set the target element to attach input to. If not called, will just use the entire document. Must be called before initializing Shaku. This can also be a method to invoke while initializing.
Kind: instance method of Input
Param | Type | Description |
---|---|---|
element | Element | elementCallback |
Element to attach input to. |
Example
// the following will use whatever canvas the gfx manager uses as input element.
// this means mouse offset will also be relative to this element.
Shaku.input.setTargetElement(() => Shaku.gfx.canvas);
Gamepad
Get Gamepad current states, or null if not connected. Note: this object does not update itself, you’ll need to query it again every frame.
Kind: instance method of Input
Returns: Gamepad
- Gamepad current state.
Param | Type | Description |
---|---|---|
[index] | Number |
Gamepad index or undefined for first connected device. |
Get gamepad id, or null if not connected to this slot.
Kind: instance method of Input
Returns: Gamepad id or null.
Param | Type | Description |
---|---|---|
[index] | Number |
Gamepad index or undefined for first connected device. |
Array.<String>
Return a list with connected devices ids.
Kind: instance method of Input
Returns: Array.<String>
- List of connected devices ids.
Set a custom key code state you can later use with all the built in methods (down / pressed / released / doublePressed, etc.)
For example, lets say you want to implement a simulated keyboard and use it alongside the real keyboard.
When your simulated keyboard space key is pressed, you can call setCustomState('sim_space', true)
. When released, call setCustomState('sim_space', false)
.
Now you can use Shaku.input.down(['space', 'sim_space'])
to check if either a real space or simulated space is pressed down.
Kind: instance method of Input
Param | Type | Description |
---|---|---|
code | String |
Code to set state for. |
value | Boolean | null |
Current value to set, or null to remove custom key. |
Boolean
Get if mouse button was pressed this frame.
Kind: instance method of Input
Returns: Boolean
- True if mouse button is currently down, but was up in previous frame.
Param | Type | Default | Description |
---|---|---|---|
button | MouseButton |
0 |
Button code (defults to MouseButtons.left). |
Boolean
Get if mouse button is currently pressed.
Kind: instance method of Input
Returns: Boolean
- true if mouse button is currently down, false otherwise.
Param | Type | Default | Description |
---|---|---|---|
button | MouseButton |
0 |
Button code (defults to MouseButtons.left). |
Boolean
Get if mouse button is currently not down.
Kind: instance method of Input
Returns: Boolean
- true if mouse button is currently up, false otherwise.
Param | Type | Default | Description |
---|---|---|---|
button | MouseButton |
0 |
Button code (defults to MouseButtons.left). |
Boolean
Get if mouse button was released in current frame.
Kind: instance method of Input
Returns: Boolean
- True if mouse was down last frame, but released in current frame.
Param | Type | Default | Description |
---|---|---|---|
button | MouseButton |
0 |
Button code (defults to MouseButtons.left). |
boolean
Get if keyboard key is currently pressed down.
Kind: instance method of Input
Returns: boolean
- True if keyboard key is currently down, false otherwise.
Param | Type | Description |
---|---|---|
key | KeyboardKey |
Keyboard key code. |
Boolean
Get if keyboard key is currently not down.
Kind: instance method of Input
Returns: Boolean
- True if keyboard key is currently up, false otherwise.
Param | Type | Description |
---|---|---|
key | KeyboardKey |
Keyboard key code. |
Boolean
Get if a keyboard button was released in current frame.
Kind: instance method of Input
Returns: Boolean
- True if key was down last frame, but released in current frame.
Param | Type | Description |
---|---|---|
button | KeyboardKey |
Keyboard key code. |
Boolean
Get if keyboard key was pressed this frame.
Kind: instance method of Input
Returns: Boolean
- True if key is currently down, but was up in previous frame.
Param | Type | Description |
---|---|---|
key | KeyboardKey |
Keyboard key code. |
Boolean
Return if a mouse or keyboard button is currently down.
Kind: instance method of Input
Returns: Boolean
- True if key or mouse button are down.
Param | Type | Description |
---|---|---|
code | string | Array.<String> |
Keyboard, touch or mouse code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState() , you can use its code here too. |
Example
if (Shaku.input.down(['mouse_left', 'touch', 'space'])) { alert('mouse, touch screen or space are pressed!'); }
Boolean
Return if a mouse or keyboard button was released in this frame.
Kind: instance method of Input
Returns: Boolean
- True if key or mouse button were down in previous frame, and released this frame.
Param | Type | Description |
---|---|---|
code | string | Array.<String> |
Keyboard, touch, gamepad or mouse button code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState() , you can use its code here too. |
Example
if (Shaku.input.released(['mouse_left', 'touch', 'space'])) { alert('mouse, touch screen or space were released!'); }
Boolean
Return if a mouse or keyboard button was pressed in this frame.
Kind: instance method of Input
Returns: Boolean
- True if key or mouse button where up in previous frame, and pressed this frame.
Param | Type | Description |
---|---|---|
code | string | Array.<String> |
Keyboard, touch, gamepad or mouse button code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState() , you can use its code here too. |
Example
if (Shaku.input.pressed(['mouse_left', 'touch', 'space'])) { alert('mouse, touch screen or space were pressed!'); }
Number
Return timestamp, in milliseconds, of the last time this key code was released.
Kind: instance method of Input
Returns: Number
- Timestamp of last key release, or 0 if was never released.
Param | Type | Description |
---|---|---|
code | string |
Keyboard, touch, gamepad or mouse button code. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState() , you can use its code here too. |
Example
let lastReleaseTime = Shaku.input.lastReleaseTime('mouse_left');
Number
Return timestamp, in milliseconds, of the last time this key code was pressed.
Kind: instance method of Input
Returns: Number
- Timestamp of last key press, or 0 if was never pressed.
Param | Type | Description |
---|---|---|
code | string |
Keyboard, touch, gamepad or mouse button code. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState() , you can use its code here too. |
Example
let lastPressTime = Shaku.input.lastPressTime('mouse_left');
Boolean
Return if a key was double-pressed.
Kind: instance method of Input
Returns: Boolean
- True if one or more key codes double-pressed, false otherwise.
Param | Type | Description |
---|---|---|
code | string | Array.<string> |
Keyboard, touch, gamepad or mouse button code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState() , you can use its code here too. |
maxInterval | Number |
Max interval time, in milliseconds, to consider it a double-press. Defaults to defaultDoublePressInterval . |
Example
let doublePressed = Shaku.input.doublePressed(['mouse_left', 'touch', 'space']);
Boolean
Return if a key was double-released.
Kind: instance method of Input
Returns: Boolean
- True if one or more key codes double-released, false otherwise.
Param | Type | Description |
---|---|---|
code | string | Array.<string> |
Keyboard, touch, gamepad or mouse button code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState() , you can use its code here too. |
maxInterval | Number |
Max interval time, in milliseconds, to consider it a double-release. Defaults to defaultDoublePressInterval . |
Example
let doubleReleased = Shaku.input.doubleReleased(['mouse_left', 'touch', 'space']);