Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: keydown repeat

  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?
    Last edited by Bobo; 01-20-2005 at 10:07 PM.
    Oh, was I supposed to put something here? ........

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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*

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Good idea!
    Tried it... works... thanks!
    Oh, was I supposed to put something here? ........


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •