Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2005, 08:20 PM   PM User | #1
Bobo
Regular Coder

 
Join Date: Jan 2004
Location: Port Huron, MI, U.S.A.
Posts: 280
Thanks: 0
Thanked 0 Times in 0 Posts
Bobo is an unknown quantity at this point
Question keydown event keeps repeating

I have a keydown event that starts a timer and clears it onkeyup.
The problem is that when you hold down the key, it acts like you're typing and repeats so rapidly that the timer clears before it calls.
This is the actual code:
Code:
var tm1;
function Move(....)
{
     ...
}
function srt(evt)
{
     tm1=setInterval("Move("+event.keyCode+")",100);
   ....
}
function end()
{
clearInterval(tm1)
}
document.onkeydown=srt;
document.onkeyup=end;
Any ideas on how to prevent the repeat or fix the code for it to not accept the rapid repeats?
__________________
Oh, was I supposed to put something here? ........

Last edited by Bobo; 01-20-2005 at 09:07 PM..
Bobo is offline   Reply With Quote
Old 01-21-2005, 12:56 AM   PM User | #2
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
Try setting a variable to true onkeydown, false onkeyup, and then put an if(!var) setInterval, or something...
__________________
*this message will self destruct in n-seconds*
codegoboom is offline   Reply With Quote
Old 01-21-2005, 09:12 PM   PM User | #3
Bobo
Regular Coder

 
Join Date: Jan 2004
Location: Port Huron, MI, U.S.A.
Posts: 280
Thanks: 0
Thanked 0 Times in 0 Posts
Bobo is an unknown quantity at this point
Good idea!
Tried it... works... thanks!
__________________
Oh, was I supposed to put something here? ........
Bobo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:50 AM.


Advertisement
Log in to turn off these ads.