example/index.js
function describeKey(e) {
    var via = '';
    var desc = [];
    if (e.getModifierState("Shift")) desc.push("Shift");
    if (e.getModifierState("Control")) desc.push("Control");
    if (e.getModifierState("Alt")) desc.push("Alt");
    if (e.getModifierState("Meta")) desc.push("Meta");
    if (e.key !== 'Unidentified') {
        desc.push(e.key);
        via = 'e.key' + (e.nativeEvent.key ? '' : ' polyfill');
    } else if (e.nativeEvent.keyIdentifier) {
        var keyId = e.nativeEvent.keyIdentifier;
        if (keyId.substring(0, 2) === 'U+') {
            var code = parseInt(keyId.substring(2), 16);
            desc.push(String.fromCharCode(code));
        } else {
            desc.push(keyId);
        }
        via = 'e.keyIdentifier';
    } else if (specials[e.which]) {
        desc.push(specials[e.which]);
        via = 'e.which + lookup';
    } else {
        desc.push(String.fromCharCode(e.which));
        via = 'e.which';
    }
    e.persist();
    console.log(e);
    return '{' + desc.join('+') + '} (' + via + ')';
}
function describeKey(e) {
    var via = '';
    var desc = [];
    if (e.getModifierState("Shift")) desc.push("Shift");
    if (e.getModifierState("Control")) desc.push("Control");
    if (e.getModifierState("Alt")) desc.push("Alt");
    if (e.getModifierState("Meta")) desc.push("Meta");
    if (e.key !== 'Unidentified') {
        desc.push(e.key);
        via = 'e.key' + (e.nativeEvent.key ? '' : ' polyfill');
    } else if (e.nativeEvent.keyIdentifier) {
        var keyId = e.nativeEvent.keyIdentifier;
        if (keyId.substring(0, 2) === 'U+') {
            var code = parseInt(keyId.substring(2), 16);
            desc.push(String.fromCharCode(code));
        } else {
            desc.push(keyId);
        }
        via = 'e.keyIdentifier';
    } else if (specials[e.which]) {
        desc.push(specials[e.which]);
        via = 'e.which + lookup';
    } else {
        desc.push(String.fromCharCode(e.which));
        via = 'e.which';
    }
    e.persist();
    console.log(e);
    return '{' + desc.join('+') + '} (' + via + ')';
}
function describeKey ( e ) { var via = '' ; var desc = [ ] ; if ( e . getModifierState ( "Shift" ) ) desc . push ( "Shift" ) ; if ( e . getModifierState ( "Control" ) ) desc . push ( "Control" ) ; if ( e . getModifierState ( "Alt" ) ) desc . push ( "Alt" ) ; if ( e . getModifierState ( "Meta" ) ) desc . push ( "Meta" ) ; if ( e . key !== 'Unidentified' ) { desc . push ( e . key ) ; via = 'e.key' + ( e . nativeEvent . key ? '' : ' polyfill' ) ; } else if ( e . nativeEvent . keyIdentifier ) { var keyId = e . nativeEvent . keyIdentifier ; if ( keyId . substring ( 0 , 2 ) === 'U+' ) { var code = parseInt ( keyId . substring ( 2 ) , 16 ) ; desc . push ( String . fromCharCode ( code ) ) ; } else { desc . push ( keyId ) ; } via = 'e.keyIdentifier' ; } else if ( specials [ e . which ] ) { desc . push ( specials [ e . which ] ) ; via = 'e.which + lookup' ; } else { desc . push ( String . fromCharCode ( e . which ) ) ; via = 'e.which' ; } e . persist ( ) ; console . log ( e ) ; return '{' + desc . join ( '+' ) + '} (' + via + ')' ; }
Produce a useful textual description of the key being handled
Produce a useful textual description of the key being handled