Obtener which y keycode
by aprudencio
HTML
<input type="text" id="test" />
<p>Which:</p>
<div id="which"></div>
<p>Keycode:</p>
<div id="keycode"></div>
<p>Alt:</p>
<div id="alt"></div>
<p>Ctrl:</p>
<div id="ctrl"></div>
<p>Shit:</p>
<div id="shift"></div>
CSS
* {
font-family: arial;
}
p {
font-weight: bold;
}
JavaScript
$("#test").focus().keydown(function(e) {
$("#test").val("");
$("#which").html(e.which);
$("#keycode").html(e.keycode);
$("#alt").html(e.altKey ? "alt pressed" : "alt key not pressed");
$("#ctrl").html(e.ctrlKey ? "ctrl pressed" : "ctrl key not pressed");
$("#shift").html(e.shiftKey ? "shift pressed" : "shift key not pressed");
});