Skip to content

Instantly share code, notes, and snippets.

@jswanner
Created December 5, 2011 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jswanner/1434211 to your computer and use it in GitHub Desktop.
Save jswanner/1434211 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>on key press test</title>
<script>
function keyPress(e) {
var keynum, keychar;
if(window.event) { // IE
keynum = e.keyCode;
}
else if(e.which) { // Netscape/Firefox/Opera
keynum = e.which;
}
keychar = String.fromCharCode(keynum);
if (window.console) {
console.log('key char: ' + keychar + ', key code: ' + keynum);
}
return true;
}
</script>
<style>
textarea {
font-size: 1.6em;
height: 200px;
width: 600px;
}
</style>
</head>
<body>
<textarea id="content" onkeypress="return keyPress(event);"></textarea>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment