/ Published in: jQuery
This jQuery plugin can be used to detect when the user smashes their keyboard.
You can set a threshold as to how many keys need to be depressed in order to trigger the event.
You can set a threshold as to how many keys need to be depressed in order to trigger the event.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(function($){ $.fn.extend({ onKeyboardSmashed : function(callbackFunction,options) { var defaults = { threshold: 3 }; var options = $.extend(defaults, options); return this.each(function() { var keys_pressed = 0 ; $(this).keydown(function(event) { keys_pressed++ if( keys_pressed >options.threshold){ if(typeof callbackFunction == 'function'){ callbackFunction.call(this); } } }); $(this).keyup(function(event) { keys_pressed--; }); }); } }); })(jQuery);
URL: http://adamcoulombe.info/lab/jquery/onkeyboardsmashed/