A practical way to create an object containing user selected hotkeys.
For example:
this.input.keyboard.addKeys({ 'up': Phaser.Input.Keyboard.KeyCodes.W, 'down': Phaser.Input.Keyboard.KeyCodes.S });
would return an object containing the properties (up
and down
) mapped to W and S Phaser.Input.Keyboard.Key objects.
You can also pass in a comma-separated string:
this.input.keyboard.addKeys('W,S,A,D');
Which will return an object with the properties W, S, A and D mapped to the relevant Key objects.
To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'.
name | type | arguments | Default | description |
---|---|---|---|---|
keys | object | string |
An object containing Key Codes, or a comma-separated string. |
||
enableCapture | boolean | <optional> | true |
Automatically call |
emitOnRepeat | boolean | <optional> | false |
Controls if the Key will continuously emit a 'down' event while being held down (true), or emit the event just once (false, the default). |
An object containing Key objects mapped to the input properties.