jQuery检测用户是否破坏了键盘

jquery-keyboard-smashed
jQuery插件,用于检测用户是否砸了键盘。 这取决于触发事件的按下键的数量……不错!

可以用来平息办公室里那些疯狂的人!

演示版

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

From: https://www.sitepoint.com/jquery-detect-user-smashes-thier-keyboard/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值