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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:51:35+00:00 2026-05-15T19:51:35+00:00

I need to detect whether the user has pressed the dot key in the

  • 0

I need to detect whether the user has pressed the dot key in the numeric keypad. I’ve written this first draft that works for me:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript"><!--
(function($){
    var knownCodes = [
        [110, 46], // Firefox, IE, Chrome
        [78, 46] // Opera
    ];
    var pressedCodes = [null, null];

    $.fn.comma = function(){
        this.live("keydown", function(e){
            pressedCodes = [e.which, null];

        }).live("keypress", function(e){
            pressedCodes[1] = e.which;

            for(var i=0, len=knownCodes.length; i<len; i++){
                if(pressedCodes[0]==knownCodes[i][0] && pressedCodes[1]==knownCodes[i][1]){
                    $("#log").append("<li>Decimal key detected</li>");
                    break;
                }
            }
        });

        return this;
    };
    $(function(){
        $('<ol id="log"></ol>').appendTo("body");
    });
})(jQuery);

jQuery(function($){
    $(".comma input:text, .comma textarea").css("border", "1px solid black").comma();
});
//--></script>
</head>
<body>

    <form action="" method="get" class="comma" size="20">
        <p><input type="text"></p>
        <p><textarea rows="3" cols="30"></textarea></p>
    </form>

</body>
</html>

However, I can only test it in a Windows XP box with a Spanish keyboard. My questions are:

  1. Is it safe to read from e.which? I’m using it because both e.keyCode and e.charCode return undefined in at least one browser.

  2. Does the operating system affect these numeric codes in some manner or it’s only a browser stuff?

  3. Do these codes depend on the keyboard layout?


Background info: I couldn’t find a jQuery plugin to remap numeric keypad so I’m writing my own.

Update

I’ll explain my exact need. Spanish keyboards that have a numeric keypad feature a . key. However, the decimal separator in Spanish is ,. That makes it annoying to type numbers in web applications. Some desktop apps like MS Excel remap this key so it inserts a comma. I’m trying to mimic that.

I’ve adapted a little script I’ve been using to post it here. That’s how I got the values for the knownCodes arrays:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript"><!--
(function($){
    $.fn.showKeyCodes = function(){
        var log = function(e){
            $("<li></li>").text(e.type + "(): [keyCode, charCode, which]=[" + e.keyCode + ", " + e.charCode + ", " + e.which + "]").appendTo("#log");
        }

        this.live("keydown", function(e){
            log(e);

        }).live("keypress", function(e){
            log(e);

        }).live("keyup", function(e){
            log(e);

        });

        return this;
    };
    $(function(){
        $('<ol id="log"></ol>').appendTo("body");
    });
})(jQuery);

jQuery(function($){
    $(".showKeyCodes input:text, .showKeyCodes textarea").css("border", "1px solid black").showKeyCodes();
});
//--></script>
</head>
<body>

    <form action="" method="get" class="showKeyCodes" size="20">
        <p><input type="text"></p>
        <p><textarea rows="3" cols="30"></textarea></p>
    </form>

</body>
</html>

Type the . key in your numeric keypad (or whatever key replaces it in your keyboard layout) and the key that corresponds to the same character in the alphabetical keypad. The goal is to detect you clicked the first one and not the second one.

  • 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-15T19:51:36+00:00Added an answer on May 15, 2026 at 7:51 pm

    Your code doesn’t do anything on my end, so I’d say it probably does depend on keyboard layout. A quick check confirms that the output on my finnish qwerty keyboard is keycode 44, instead of the expected 46.

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

Sidebar

Related Questions

I would like to detect whether the user has pressed Enter using jQuery. How
I need to detect whether my application is running within a virtualized OS instance
I need to detect whether my Makefile is running under valgrind (indirectly, using valgrind
I need to detect when a session has expired in my Visuial Basic web
I need a way to programatically detect whether the monitor is wide or not,
I need to detect Image format to save a image like image1.jpg, image2.gif, but
For my current C++ project I need to detect a unique string for every
For a windows script I am writing, I need to detect if the machine
I am writing a Browser Helper Object for ie7, and I need to detect
How does the HttpBrowserCapabilities.Crawler property ( http://msdn.microsoft.com/en-us/library/aa332775(VS.71).aspx ) work? I need to detect 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.