Hi, I'm writing a plugin for jQuery for catching 2 succesive keypresses. I'll paste the plugin I wrote below . It doesn't work on Opera . The Developer tools of Opera gave no errors and I can't find any problems, it just doesn't work. (I've used Opera 10.0). So it only works on Firefox (tested on 3.0.14). I'm curious if there is a way to find out why it's not working on Opera and to fix it. Here's the code:
26 /* 27 * this is a plugin for binding double key combinations to some callback 28 * it works by storing the first_press in the global jQuery namespace , a boolean value which indicates 29 * the first key has already been pressed (but it's updated to 'false' in delay time. 30 * in teh meanwhile if someone presses the secondKey and the $.first_press is true , the callback will execute 31 * with the $(this) passed as parameter so it ca modify it 32 */ 33 34 $.fn.keypressTwice = function(firstKey,secondKey,actualCallback) { 35 var stuff = $(this); 36 var delay = 1000; 37 stuff.keypress(function(e){ 38 if($.first_press) { 39 if(String.fromCharCode(e.charCode)==secondKey) { 40 //alert('secondKey'); 41 actualCallback(stuff); 42 $.first_press = false; 43 } 44 } else if(String.fromCharCode(e.charCode)==firstKey) { 45 //alert('firstKey'); 46 $.first_press = true; 47 window.setTimeout(function() { 48 $.first_press= false; 49 }, delay); 50 }; 51 e.stopPropagation(); 52 }); 53 } Thanks for taking the time to read this. Best regards, Stefan