function create() {
  /*
    A data structure to keep track of the currently pressed keys and
    the last pressed key
   */
  const keys = {
    pressed: [
      0, 0, 0, 0,
      0, 0, 0, 0, 
      0, 0, 0, 0, 
      0, 0, 0, 0
    ],
    lastPressed: -1
  };

  /**
   * Callback to handle key down events.
   * If the pressed key is one of the accepted by Chip-8, it is
   * stored in memory as pressed
   * @param {Object} event keyDown event
   */
  function onKeyDown(event) {
    const { key } = event;
    const index = keyMap.indexOf(key);
    if (index > -1) {
      keys.pressed[index] = 1;
      keys.lastPressed = index;
    };
  }

  /**
   * Callback to handle key up events.
   * If the released key is one of the accepted by Chip-8, it is
   * stored in memory as released
   * @param {Object} event keyDown event
   */
  function onKeyUp(event) {
    const { key } = event;
    const index = keyMap.indexOf(key);
    if (index > -1) {
      keys.pressed[index] = 0;
      keys.lastPressed = -1;
    };
  }

  return { keys, onKeyDown, onKeyUp };
}
/**
 * Creates a data structure to keep track of the pressed keys during the emulation
 * and provides the callback functions to handle keyup/keydown events
 * @returns { Object } The keys data structure, onKeyDown and onKeyUp callbacks
 */
Creates a data structure to keep track of the pressed keys during the emulation
and provides the callback functions to handle keyup/keydown events
@returns { Object } The keys data structure, onKeyDown and onKeyUp callbacks
Creates a data structure to keep track of the pressed keys during the emulation and provides the callback functions to handle keyup / keydown events @returns { Object } The keys data structure onKeyDown and onKeyUp callbacks
function create() {
  const keys = {
    pressed: [
      0, 0, 0, 0,
      0, 0, 0, 0, 
      0, 0, 0, 0, 
      0, 0, 0, 0
    ],
    lastPressed: -1
  };
  function onKeyDown(event) {
    const { key } = event;
    const index = keyMap.indexOf(key);
    if (index > -1) {
      keys.pressed[index] = 1;
      keys.lastPressed = index;
    };
  }
  function onKeyUp(event) {
    const { key } = event;
    const index = keyMap.indexOf(key);
    if (index > -1) {
      keys.pressed[index] = 0;
      keys.lastPressed = -1;
    };
  }
  return { keys, onKeyDown, onKeyUp };
}
function create ( ) { const keys = { pressed : [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , lastPressed : - 1 } ; function onKeyDown ( event ) { const { key } = event ; const index = keyMap . indexOf ( key ) ; if ( index > - 1 ) { keys . pressed [ index ] = 1 ; keys . lastPressed = index ; } ; } function onKeyUp ( event ) { const { key } = event ; const index = keyMap . indexOf ( key ) ; if ( index > - 1 ) { keys . pressed [ index ] = 0 ; keys . lastPressed = - 1 ; } ; } return { keys , onKeyDown , onKeyUp } ; }
Creates a data structure to keep track of the pressed keys during the emulation
 and provides the callback functions to handle keyup/keydown events
 @returns { Object } The keys data structure, onKeyDown and onKeyUp callbacks
Creates a data structure to keep track of the pressed keys during the emulation and provides the callback functions to handle keyup / keydown events @returns { Object } The keys data structure onKeyDown and onKeyUp callbacks
/*
    A data structure to keep track of the currently pressed keys and
    the last pressed key
   */ /**
   * Callback to handle key down events.
   * If the pressed key is one of the accepted by Chip-8, it is
   * stored in memory as pressed
   * @param {Object} event keyDown event
   */ /**
   * Callback to handle key up events.
   * If the released key is one of the accepted by Chip-8, it is
   * stored in memory as released
   * @param {Object} event keyDown event
   */