jquery-keyboard-smashed
jQuery plugin to detect if a user has smashed their keyboard. This is determined by the amount of keys that are depressed which triggers the event… nice!

Could be used to calm down those crazy people in the office!

Demo

(function($){
 $.fn.extend({
 
 	onKeyboardSmashed : function(callbackFunction,options) {
		var defaults = {
			//change here for event trigger
			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);
//usage
$(document).onKeyboardSmashed(function(){
	$("#status").html('keyboard smashed');
	$("#msg").hide();
});
Sam Deering Sam Deering
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

No Reader comments

Related books & courses
Available now on SitePoint Premium

Preview for $1