Posted By

adamcoulombe on 03/29/10


Tagged

event key jquery keyboard keydown onKeyboardSmashed smash smashed mash mashed javascriptplugin


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jfherring


jQuery onKeyboardSmashed event Plugin


 / Published in: jQuery
 

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

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.

  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);

Report this snippet  

You need to login to post a comment.