jQuery onKeyboardSmashed event Plugin


/ Published in: jQuery
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. (function($){
  2. $.fn.extend({
  3.  
  4. onKeyboardSmashed : function(callbackFunction,options) {
  5. var defaults = {
  6. threshold: 3
  7. };
  8.  
  9. var options = $.extend(defaults, options);
  10.  
  11.  
  12. return this.each(function() {
  13.  
  14. var keys_pressed = 0 ;
  15. $(this).keydown(function(event) {
  16. keys_pressed++
  17.  
  18. if( keys_pressed >options.threshold){
  19. if(typeof callbackFunction == 'function'){
  20. callbackFunction.call(this);
  21. }
  22. }
  23. });
  24.  
  25. $(this).keyup(function(event) {
  26. keys_pressed--;
  27. });
  28.  
  29. });
  30.  
  31. }
  32. });
  33. })(jQuery);

URL: http://adamcoulombe.info/lab/jquery/onkeyboardsmashed/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.