Skip to content

Instantly share code, notes, and snippets.

@codeachange
codeachange / jquery.dblkeydown.js
Created December 11, 2013 15:50
jQuery double keydown plugin, detect double keydown(same key pressed twice) event
(function($){
$.fn.dblkeydown = function(keyCode, callback){
return $(this).keydown(function(e){
if (e.which == keyCode) {
var lastTime = $(this).data('dblkeydown_' + keyCode);
var curTime = new Date().getTime();
if (lastTime && (curTime - lastTime < $.fn.dblkeydown.maxInterval)) {
$(this).data('dblkeydown_' + keyCode, null);
callback.call(this);
}else{