JSFiddle - React, Tailwind, and code Playground
HTML
ddddddddddddddddddddsdfdsafdsafdsafsa
JavaScript
$(document).ready(function(){
var dispatcher = $(window),
keyRate = 1000, //ms
lastKeyEvent = 0,
cancelEvent = function(e){
var evt = e ? e:window.event;
if(evt.stopPropagation)
evt.stopPropagation();
if(evt.cancelBubble!=null)
evt.cancelBubble = true;
return false;
};
dispatcher
.bind('keydown',function(e){
var now = new Date().getTime(),
keyEventsTimeDiff = now - lastKeyEvent;
if(keyEventsTimeDiff <= keyRate)
// cancel the event
return cancelEvent(e);
lastKeyEvent = now;
dispatcher.trigger('special-keydown',[e,keyEventsTimeDiff]);
})
.bind('keyup',function(e){
cancelEvent(e);
dispatcher.trigger('special-keyup',[e]);
})
// binding the custom events
.bind('special-keydown',function(e,originalEvent,keyEventsTimeDiff){
console.log(originalEvent,'special keydown triggered again after ' + keyEventsTimeDiff +'ms');
})
.bind('special-keyup',function(e,originalEvent,keyEventsTimeDiff){
console.log(originalEvent,'special keyup');
});
});