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

  • SEARCH
  • Home
  • 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 8190083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:30:03+00:00 2026-06-07T03:30:03+00:00

The objective is manually set a held key’s repeat rate. For example, when in

  • 0

The objective is manually set a held key’s “repeat rate”.

For example, when in a text box and pressing and holding the X key, I understand that there is browser-specific ways of repeating the pressed character. In some, it pauses, then continuously triggers the pressed key. In others, it doesn’t repeat at all. I want to mitigate this by forcing the pressed key to repeat at a specific interval, regardless of browser.

Through research, I’ve come up with a timer-based attempt, but in Safari, it does not repeat the character. I’ve got a menu system where holding down arrow scrolls through the list, but the translation animation and repeat rate don’t like each other.

var repeating = false;
var repeatRateTimer = null;

$( document ).bind( 'keyup', function( input ) {
    if( repeatRateTimer != null )
    {
        clearTimeout( repeatRateTimer );
        repeatRateTimer = null;
    }

    repeating = false;
} );

$( document ).bind( 'keydown', function( input ) {
    input.preventDefault( );

    if( repeating == true )
    {
        if( repeatRateTimer != null )
        {
            clearTimeout( repeatRateTimer );
            repeatRateTimer = null;
        }
        else
        {
            repeatRateTimer = setTimeout( function( ){ repeating = false; }, 1000 );
        }

        return;
    }
    repeating = true;

    // ...keyboard logic
} );

I may have botched this whole thing up…I tried to recreate a simplified version of this SO post. However, I feel there has to be a better way of doing this. Any thoughts?

Update:

We can assume that the end-user hasn’t set their OS keyboard repeat rate greater than the rate I want to use (1000ms). If it is, then it should fall back to their repeat rate, since it won’t keep triggering the key press event. If it isn’t (more likely since most people don’t modify that), then we would be overriding that behavior to make it delay our specified period.

  • 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-06-07T03:30:05+00:00Added an answer on June 7, 2026 at 3:30 am

    Well, I figured out why my example wasn’t looping. In the keydown loop, it was clearing the timeout before it expired:

    if( repeatRateTimer != null )
    {
        clearTimeout( repeatRateTimer );
        repeatRateTimer = null;
    }
    else
    {
        repeatRateTimer = setTimeout( function( ){ repeating = false; }, 1000 );
    }
    

    The timeout should be cleared only after it expires, so the if condition needed to be moved into the timeout function:

    if( repeatRateTimer == null )
    {
        repeatRateTimer = setTimeout( function( ) {
            repeating = false;
            clearTimeout( repeatRateTimer );
            repeatRateTimer = null;
        }, 1000 );
    }
    

    I’ll leave this bounty open in case someone can improve upon this, or provide a better alternative.

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

Sidebar

Related Questions

Objective: I want to create a web service that allows me to connect to
Objective: In support of a Windows Service that may have multiple instances on a
The objective is to write a convenience method that return a ResultSet from a
I am using C++ as the app backbone and Objective-C for the GUI, that's
In our application I have a routine that manually iterates over the properties of
In Objective-C, it's common to override -description with a method that prints the object
I'm building a static library, MyLibrary , for iOS in Objective-C that bundles together
I understand that dividing by int (0) raises a flag and not an exception
In xcode4/Objective C, on Leopard: I have a CGDisplayModeRef which is as I understand
My objective is to set a cookie from within a servlet called from a

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.