Created
April 24, 2013 21:25
-
-
Save sgreenfield/5455709 to your computer and use it in GitHub Desktop.
monitors keypress events and fires different event depending on whether or not the keypress actually produces a character with a value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function($){ | |
//monitors keypress events and fires different event depending on whether or not the keypress actually produces a character with a value | |
$.fn.keylogger = function() { | |
return this.each(function() { | |
$(this).keypress(function(e) { | |
if ( hasValue(e) ) $(this).trigger( 'keylogger:withvalue', [String.fromCharCode(e.charCode), e] ); | |
else $(this).trigger( 'keylogger:novalue', e ); | |
}); | |
}); | |
function hasValue(e){ | |
var code = (e.keyCode) ? e.keyCode : e.which; | |
return (e.charCode && code !== 32 && code !== 13 && !e.altKey && !e.ctrlKey && !e.metaKey); | |
} | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment