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 7405075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:20:54+00:00 2026-05-29T05:20:54+00:00

This is probably intended behaviour or atleast not a jQuery / js issue but

  • 0

This is probably intended behaviour or atleast not a jQuery / js issue but I’d like some clarification if there’s any to be had.

Take the following:

$(document).bind('keypress', function(e){
    switch(e.keyCode)
    {
        case 37:
            console.log('left cursor keydown, will fire on hold');
            break;
        case 39:
            console.log('right cursor keydown, will fire on hold');
            break;
        case 80:
            console.log('p will only fire once per press!');
            break;
    }
});

You can also play with the example at jQuery’s docs: http://api.jquery.com/keypress/

When a left or right cursor is pressed (or many other keys such as A,E,[, etc), the event fires and you get a nice log message in the console. All fine & as intended. However, now try holding the key down – after a brief pause you will see that the keydown event fires multiple times when you hold the key, however if you try hitting a p (or, for instance, a j), it will only fire once.

I’m testing this using FF 9.0.1 and mac OSX 10.7.1 and jQuery 1.7.1.

Is this by design, is it a browser-dependant feature, or is it to do with the OS, or even the keyboard itself? Also has anyone got a list of keys that will repeat and keys that will not?

As far as the use case goes, there isn’t one really – this just cropped up when I was binding an animation to a cursor press and started seeing wierd behaviour when the key was pressed. My workaround was to use the keyup() event instead, and preventDefault() on the keydown() event for the keys I was insterested in, to stop the cursors scrolling the screen.

UPDATE:
Seems that on the keypress event, keyCode is always 0 for most letters, which might have something to do with why I thought the handler only fired once. After some more testing I see the repeated log entries like for cursors. If you check the jQuery API page though, and use the demo on that, it exhibits the behaviour I was describing: http://api.jquery.com/keypress/

Still can’t explain that myself :/

  • 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-29T05:20:55+00:00Added an answer on May 29, 2026 at 5:20 am

    Behaviour varies between browsers and operating systems. The following page covers the topic of auto-repeated key events in detail in section 2.2:

    http://unixpapa.com/js/key.html

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

Sidebar

Related Questions

This probably has a simple answer, but I must not have had enough coffee
There's probably other ways of doing this but I'd like to use an empty
This probably sounds really stupid but I have noo idea how to implement jquery's
This probably sounds like a terrible idea at first glance, but here is my
I know this probably really simple but Im not sure what im doing wrong...
This is probably trivial, and I do have a solution but I'm not happy
I am using ASP.Net MVC but this probably applies to all MVC patterns in
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my
Ok, this probably has a really simple answer, but I've never tried to do
OK, this probably is supposed to be the easiest thing in the world, but

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.