javascript get keycode from keyboard event

by Rich Costello

JavaScript

function handler(e) {
    var key = window.event ? e.keyCode : e.which;
    console.log(key, e.shiftKey, e.altKey, e.ctrlKey);
}


function keytest() {
	if (document.attachEvent) document.attachEvent('onkeydown', handler);
	else document.addEventListener('keydown', handler);
}

keytest();