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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:01:16+00:00 2026-05-25T02:01:16+00:00

My code is $(‘input’).live(‘keypress’, function(event) { if (event.keyCode === 37) console.log(left key pressed); else

  • 0

My code is

$('input').live('keypress', function(event) {
   if (event.keyCode === 37) console.log("left key pressed");
    else console.log("some other key press");
});

Please see http://jsfiddle.net/4RKeV/

This detects keypresses, but not the left keypress (keyCode 37). How can I detect left keypress?

  • 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-25T02:01:17+00:00Added an answer on May 25, 2026 at 2:01 am

    In short: don’t use the keypress event. Use keydown or keyup instead.

    The keypress event is not covered by any official specification. As such, keypress does not have well-defined behavior, will not work the same way across browsers, and will act capriciously and unpredictably. (Read more [quirksmode.org])

    As an alternative to keypress, you should use one of these events:

    • keydown [w3c spec] — This triggers when a key is pressed down and continues to trigger while the key is held down.
    • keyup [w3c spec] — This triggers when the key is lifted up.

    I would probably fix it by using keydown because it is probably closer to what you were expecting keypress to do:

    $('input').live('keydown', function(e) { 
       if (e.which === 37) { console.log("left key pressed"); }
       else { console.log("some other key press"); }
    }); 
    

    P.S. I changed e.keyCode to e.which, because it is more cross-browser compliant.

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

Sidebar

Related Questions

Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();
Code I have: cell_val = CStr(Nz(fld.value, )) Dim iter As Long For iter =
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
Code below is not working as expected to detect if it is in design
Code like this often happens: l = [] while foo: # baz l.append(bar) #
Code that is untestable really annoys me. The following things make oo-code untestable: global
(code examples are python) Lets assume we have a list of percentages that add
code snippet: //byte[] myByteArray = byte array from database (database BLOB) myByteArray = (byte[])
Code: for i in {0..3}; do ping http://www.pythonchallenge.com/pc/def/$i.html; done A host should be found

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.