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

The Archive Base Latest Questions

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

I wrote the following code (using jQuery) to show the pressed key. $(window).keydown(function(e){ $(div).text(Key:

  • 0

I wrote the following code (using jQuery) to show the pressed key.

$(window).keydown(function(e){
  $("div").text("Key:" + String.fromCharCode(e.keyCode).toLowerCase());
  return false;
});

This code works in normal alphabet characters (q,w,e,r…).
But when I press non alphabet keys (like ‘]’), an incorrect character is shown.

ex: ‘,’ -> ¼, ‘]’ -> ý

What’s wrong with my code?

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

    Use the keypress event and e.which property.

    jQuery normalizes the keycodes, and stores the variable in event.which. The keypress event’s which property is the only reliable value for String.fromCharCode.

    The event.keyCode property may not be equal to the event.charCode or event.which properties.

    For non-printable characters, event.which has a value of zero, contrary to event.keyCode. That’s why you’re seeing weird characters.

    $(window).keypress(function(e) {
        var charCode = e.which;
        if (!charCode) { // <-- charCode === 0
            return;// return false, optionally
        }
        $("div").text("Key:" + String.fromCharCode(charCode).toLowerCase());
        return false; // Or e.preventDefault(); and/or e.stopPropagation()
    }).keyup(function(e) {
        // Key is lifted, do something
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
I'm working with the jQuery Validation plugin and I wrote the following code which
I needed some simple string encryption, so I wrote the following code (with a
I'm loading jQuery via Google's CDN using the following code. My main question is
I would like to write a function using jQuery to append a div to
I have been using the following code for loading JQuery in all of my
I'm trying to write my own modal popup window using a jQuery function. However,
I'm using the following code to write data through a named pipe from one
I am using the following code to determine if I can write to 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.