JSFiddle - React, Tailwind, and code Playground

by octatone

HTML

<script src="https://raw.github.com/documentcloud/underscore/master/underscore-min.js"></script>

JavaScript

$('body').on('keydown', function (e) {
    
    console.log(getKeys(e));
});

function getKeys (e) {
    
    var ignore = [16, 17, 18, 91, 93, 13, 27];
    var modifiers = ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'];
    var val = false;
    var char = String(String.fromCharCode(e.which));
    
    console.log(e.which);
    
    if (_.include(ignore, e.which)) {
        
        return val;
    }
    
    _.each(modifiers, function (modifier) {
                
        if (e[modifier] === true) {
            
            modifier = modifier.replace('Key', '');
            
            if (val) {
                val += '+'+modifier;
            }
            else {
                val = modifier;
            }
        }
    });
    
    if (!val) {
        val = char;
    }
    else {
        val += '+'+char;
    }
    
    return val;
}