i need a script that detects all the long or continous key presses on all browsers

I have a script that detects long down key press in opera but not in firfox mozilla..Why is that happening??

Iam using this code:-

    oEvent=window.event || oEvent;

       case 38: //up arrow
       case 40: //down arrow
       case 13: //return key
       case 27: //escape key

This detects my long down key press in opera but not in mozilla .Please suggest me a solution so that my long key presses works fine in all browsers.

EDIT: from long key presses i meant continous key press here.like continous down key press.


for cross browsing use keyCode and which

var ikeyCode = oEvent.keyCode || oEvent.which ;

now you can detect in all browsers

What I'd try is to watch the keydown keyup events instead of keypress. When the keydown occurs, write the time to a variable and start a timer with setTimeout. If keyup happens within maybe 0.3 seconds (so compare the stored time with the current time when this event fires) consider it a tap and call whatever function you need to for that and clear setTimeout. If your timer reaches 3 seconds like in your example before keyup has been fired, then the user held the button down so show an alert. Hope that makes sense. I haven't tried it but it sounds good in my head. LOL

i got the solution... i was using oText.onkeydown=this.keyDown; where i should have used oText.onkeypress=this.keyDown;

Thanks all for your help!

Need Your Help

Python logging: Why is __init__ called twice?

python logging handler config init

I am trying to use python logging with a config file and an own handler. This works to some degree. What really puzzle me is __init__ being called twice and __del__ being called once. When I remove...

Checking for existing users in DB using Ajax and PHP

php jquery ajax

I'm running into a problem where the code keeps on showing that the user name is available, even though it is existing in the DB. Can anyone solve the problem that I'm running into? Down below is my

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.