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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:39:01+00:00 2026-06-04T12:39:01+00:00

I take what the user typed using event.which on a keypress, and output using

  • 0

I take what the user typed using event.which on a keypress, and output using String.fromCharCode.

User types: a
event.which: 67
Outputs: A

For numbers and letters I can handle, but when talking about special characters, I get totally different outputs.

User types: –
event.which: 189
Outputs: ½

After a research, I came across the function charCodeAt, and using this one, the output comes perfectly, even special characters.

Unfortunately, I can’t use charCodeAt because the user types directly from the $(document), and not from a field.

So, the question is, is there a way I can get the right charCode from the keyPress event.which?

If still can’t figure out my doubt, I made you a Fiddle =)

  • 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-04T12:39:03+00:00Added an answer on June 4, 2026 at 12:39 pm

    Use the keypress event instead of keyup. It reports character code instead of key codes, and it triggers when actual characters are typed, not when a key is released, so it handles repeated characters too.

    $('#field').focus().keypress(function(e){
      var key = e.which;
      $("#key").val(String.fromCharCode(key));
    });
    

    http://jsfiddle.net/Guffa/QCHt7/1/

    Edit:

    If you want to catch keypresses everywhere, you have to hook up the event on the document, and also on any elements that consumes keypresses. A textbox for example will handle the keypress and won’t let it bubble up to the parent element.

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

Sidebar

Related Questions

I'm developing an app where the user can take up to 3 photo's which
how to take user input in Array using Java? i.e we are not initializing
Take tables: User, Comment, Snippet. A User can have many Snippets. A Snippet can
I use an API that expects a SQL string. I take a user input,
i tried to take input from user input type is not determined(can be char
A user types any text in the textarea on html page. The string is
I'd like to take user input (sometimes this will be large paragraphs) and generate
I'm trying to take user form input and display it back to the user,
I want to take a user OUT of my app and into the App
After clicking on a UIView I want to take the user of my app

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.