Inputs

Handles key and mouse inputs

Constructor

new Inputs()

Methods

blockRightClick()

Call to disable the context menu when the user right clicks the window

isValidKeyEvent(event) → {boolean}

Checks if a key input name is valid and formatted correctly

Parameters:
NameTypeDescription
eventstring

Name of key bind

Returns:

If the event is formatted correctly

Type: 
boolean

isValidMouseEvent(event) → {boolean}

Checks if a mouse input name is valid and formatted correctly

Parameters:
NameTypeDescription
eventstring

Name of key bind

Returns:

If the event is formatted correctly

Type: 
boolean

isPressed(…keys) → {boolean}

Check if key(s) are currently being pressed

Parameters:
NameTypeAttributesDescription
keysstring<repeatable>

Key to check

Returns:

If the set of keys is pressed

Type: 
boolean
Example
inputs.isPressed("d");
inputs.isPressed("ctrl", "alt", "shift", "s"); // can be in any order

on(event, callback)

Bind a callback to an event

Parameters:
NameTypeDescription
eventstring

Keys pressed in event

callbackfunction

Callback run when event is fired

Example
// key events
inputs.on("a", keydown => { // called when 'a' is pressed down or up
	if (keydown) { // 'a' key is depressed
		// do some logic
	}
	else { // 'a' key is no longer depressed
		// logic
	}
});
inputs.on("altW", keydown => {}); // alt + w
inputs.on("ctrlAltShiftH", keydown => {}); // ctrl + alt + shift + h. Must be in this order, but can take out ctrl/alt/shift as needed
inputs.on(" ", keydown => {}); // space is pressed

// mouse events
inputs.on("mouse0", mousedown => {}); // left click
inputs.on("mouse1", mousedown => {}); // middle click
inputs.on("mouse2", mousedown => {}); // right click

off(event, callback)

Unbinds a callback from an event

Parameters:
NameTypeDescription
eventstring

Keys pressed in event

callbackfunction

Function to unbind

trigger(event, …args)

Triggers an event, firing all bound callbacks

Parameters:
NameTypeAttributesDescription
eventstring

Name of the event

args*<repeatable>

Arguments passed to callbacks