Skip to content

Instantly share code, notes, and snippets.

@paulspringett
Created May 1, 2012 14:33
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 paulspringett/2568346 to your computer and use it in GitHub Desktop.
Save paulspringett/2568346 to your computer and use it in GitHub Desktop.
Bind a function to escape keypress
# $.esc
# Binds the given callback function to the keyup
# event for the "Escape" key
# Example usage:
# $.esc(function(event) {
# alert("Escape key pressed!");
# });
# Compatible with jQuery or Zepto
$.esc = (callback) ->
$(document).on 'keyup', (event) ->
callback?(event) if event.keyCode is 27
@paulspringett
Copy link
Author

Example use:

$.esc(function(event) {
  alert("Escape key pressed!");
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment