UNPKG

substance

Version:

Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing system. It is developed to power our online editing platform [Substance](http://substance.io).

26 lines (24 loc) 610 B
export { default as keys } from './keys' /** * Generates a normalized key from a records similar to a DOM KeyboardEvent. * * @param {object} event * @param {boolean} onlyModifiers */ export default function parseKeyEvent (event, onlyModifiers) { const frags = [] if (event.altKey) { if (event.code === 'AltRight') { frags.push('ALTGR') } else { frags.push('ALT') } } if (event.ctrlKey) frags.push('CTRL') if (event.metaKey) frags.push('META') if (event.shiftKey) frags.push('SHIFT') if (!onlyModifiers) { frags.push(event.keyCode) } return frags.join('+') }