Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6372609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:15:37+00:00 2026-05-25T01:15:37+00:00

I have a javascript function which runs when the ‘down’ key is pressed. I

  • 0

I have a javascript function which runs when the ‘down’ key is pressed. I would like, that if the ‘down’ key is held down, the function would not run at all.

I thought about timing between keydown and keyup, if the time is less than 1 second then the function would run on keyup. The problem is, if I hold the key down the browser sees it as the key being pressed many times in succession.

Is there a better way to do this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:15:38+00:00Added an answer on May 25, 2026 at 1:15 am

    If I understand your problem is that your browser interprets a key being held as multiple keydown events.
    You want something different to happen if a key is held versus when it’s simply pressed; and you want that difference to be based on some time which you think should constitute “holding” the key.
    So you need to differentiate between a hold and a press by tracking the keyup event. The following pseudocode will resolve this problem:

    On Keydown:

    if !yourBool 
        start timer
    
    yourBool = true 
    

    on Keyup:

    if timer < yourTime
        do something
    
    yourBool = false
    

    This will work because the timer will not restart unless keyup event has occurred.

    Now… if your browser interprets key holding as:
    Keydown, Keyup, Keydown, Keyup…….
    then you have a problem with this approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like a JavaScript function to have optional arguments which I set a
I have the following JavaScript code: Link In which the function makewindows does not
I have some javascript which runs a timer that animates something on the website.
I have a Javascript function show() { alert(hello); } which runs on ASP Button
I have this line of Javascript which runs a function I sourced online. However
I have a bit of javascript that runs on a 3rd party's website which
I have a javascript function which runs when a script button is clicked, //script
I have a JavaScript function which is quite long and performs a number of
I have a little javascript function which is attached to an onClick event of
We have a JavaScript function named move which does just windows.location.href = any given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.