Skip to content

Instantly share code, notes, and snippets.

@junaidk
Forked from bennadel/key_combo.htm
Created January 1, 2014 16:13
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 junaidk/8209169 to your computer and use it in GitHub Desktop.
Save junaidk/8209169 to your computer and use it in GitHub Desktop.
<!doctype>
<html>
<head>
<title>Detecting Key-Combo Events With jQuery</title>
<script type="text/javascript" src="./jquery-1.7.1.js"></script>
<script type="text/javascript">
// Run when the DOM has loaded.
$(function(){
// Let's define a generic event handler that will look at
// the key being pressed and log it out to the console.
var keyHandler = function( event ){
var keyCode = event.which;
var keyChar = String.fromCharCode( keyCode );
// Log the key captured in the event data.
console.log(
event.type + " : " + keyChar + " (" + keyCode + ")"
);
};
// Now, let's try binding both the key-down and key-press
// events to listen for the key and combos.
$( "input" ).on( "keydown keypress", keyHandler );
});
</script>
</head>
<body>
<h1>
Detecting Key-Combo Events With jQuery
</h1>
<form>
<input type="text" value="" size="30" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment