Keyboard

new Keyboard(keyModObjsopt, defaultModifieropt)

Creates an instance of Keyboard.

Parameters:
NameTypeAttributesDefaultDescription
keyModObjsObject<optional>
[]

an array of objects

defaultModifier*<optional>

if no modifier, use the default if given The objects in the keyModObjs look like: { modifier: 'alt', key: 's', cmd: () => anim.start() } If modifier = '', then no modifier is used

The cmd is generally an arrow function to insure it executes in the caller's name space

Example: const keyModCmds = [ // These use the default modifier key, in this case the 'alt' key { key: 'q', cmd: () => console.log('q') }, { key: 'w', cmd: () => console.log('w') }, { key: '2', cmd: () => console.log('2') }, { key: 'F2', cmd: () => console.log('F2') }, { key: 'Backspace', cmd: () => console.log('Backspace') }, { key: 'ArrowDown', cmd: () => console.log('ArrowDown') }, { key: 'Enter', cmd: () => console.log('Enter') }, { key: 'Escape', cmd: () => console.log('Escape') }, // Here we override the default modifier key { modifier: 'shiftKey', key: 'a', cmd: () => console.log('shift A') }, { modifier: 'None', key: 'b', cmd: () => console.log('b') }, { modifier: '', key: 'c', cmd: () => console.log('c') } ] const keyboard = new Keyboard(keyModCmds, 'alt')

Methods

start()

Start the keyboard running

stop()

Stop the keyboard running