Created
January 4, 2012 00:19
-
-
Save pifantastic/1557738 to your computer and use it in GitHub Desktop.
jQuery keyhold plugin. Records the number of milliseconds a key is pressed.
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($) { | |
var k = {}; | |
$(window).bind('keydown', function(e) { | |
if (!k[e.which]) { | |
k[e.which] = +new Date; | |
} | |
}); | |
$(window).bind('keyup', function(e) { | |
e.duration = new Date - k[e.which]; | |
e.type = 'keyhold'; | |
delete k[e.which]; | |
$(e.target).trigger(e); | |
}); | |
})(jQuery); |
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(a){var b={};a(window).bind("keydown",function(a){b[a.which]||(b[a.which]=+(new Date))}),a(window).bind("keyup",function(c){c.duration=new Date-b[c.which],c.type="keyhold",delete b[c.which],a(c.target).trigger(c)})})(jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment