Methods
blockRightClick()
Call to disable the context menu when the user right clicks the window
- Source
isValidKeyEvent(event) → {boolean}
Checks if a key input name is valid and formatted correctly
Parameters:
Name | Type | Description |
---|---|---|
event | string | Name of key bind |
- Source
Returns:
If the event is formatted correctly
- Type:
- boolean
isValidMouseEvent(event) → {boolean}
Checks if a mouse input name is valid and formatted correctly
Parameters:
Name | Type | Description |
---|---|---|
event | string | Name of key bind |
- Source
Returns:
If the event is formatted correctly
- Type:
- boolean
isPressed(…keys) → {boolean}
Check if key(s) are currently being pressed
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
keys | string | <repeatable> | Key to check |
- Source
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:
Name | Type | Description |
---|---|---|
event | string | Keys pressed in event |
callback | function | Callback run when event is fired |
- Source
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:
Name | Type | Description |
---|---|---|
event | string | Keys pressed in event |
callback | function | Function to unbind |
- Source
trigger(event, …args)
Triggers an event, firing all bound callbacks
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
event | string | Name of the event | |
args | * | <repeatable> | Arguments passed to callbacks |
- Source