On this page

# Keyboard

### new Keyboard(Commands, ModifierKey)

Creates an instance of Keyboard. The objects in the keyModObjs look like:

Parameters:

Name | Type | Description
--- | --- | ---
`Commands` | Array.<Object> | array of keyboard command objects
`ModifierKey` | String | default modifier key(alt, shift, ..)

Source
  - Keyboard.js, line 37

Examples

    // A command object looks like:
    {
        key: 's',
        cmd: () => anim.start(),
        modifier: 'alt', // if messing, use the constructor's default modifier
    }

    // The array of keyboard commands looks like:
     const keyCommands = [
         // These use the default modifier key, in this case the 'alt' key
         { key: 'q', cmd: () => console.log('q') },
         { key: '2', cmd: () => console.log('2') },
         { key: 'F2', cmd: () => console.log('F2') },
         { key: 'ArrowDown', cmd: () => console.log('ArrowDown') },
         { 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(keyCommands, 'alt')

## Methods

### start()

Start the keyboard running

Source
  - Keyboard.js, line 84

### stop()

Stop the keyboard running

Source
  - Keyboard.js, line 113

Type anything to view search result