jQuery Event object has different keycode in keypress and keyup
Is this on purpose? IE and Safari behave the same, Firefox is
different. Here's my little tester. In particular, try the keypad:
<html>
<script type="text/javascript" src="http://code.jquery.com/jquery-
latest.pack.js"></script>
<script language="javascript">
$( function() {
$('#KeyTester')
.keypress( function( jqe ){
var ch = String.fromCharCode(jqe.keyCode);
$('#KeyPressResult').text( ch + ' [' + jqe.keyCode +
']' );
$(this).val(ch);
jqe.preventDefault();
})
.keyup( function(jqe){
var ch = String.fromCharCode(jqe.keyCode);
$('#KeyUpResult').text( ch + ' [' + jqe.keyCode +
']' );
});
});
</script>
<body>
<table>
<tr>
<td>Type character</td>
<td><input type="text" id="KeyTester" size=4 value=""/></td>
</tr>
<tr>
<td>KeyPress character</td>
<td><span id="KeyPressResult"/></td>
</tr>
<tr>
<td>KeyUp character</td>
<td><span id="KeyUpResult"/></td>
</tr>
</table>
</html>