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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:18:03+00:00 2026-05-15T11:18:03+00:00

<html> <head> <title>Test</title> <script type=text/javascript> function showChar(e) { if (e.keyCode != 16) { alert(

  • 0
<html>
<head>
<title>Test</title>

<script type="text/javascript">

function showChar(e) {
    if (e.keyCode != 16) {
        alert(
           "keyCode: " + e.keyCode + "\n"
          + "SHIFT key pressed: " + e.shiftKey + "\n"
        );
    }
}

</script>
</head>

<body onkeydown="showChar(event);">
<p>Press any character key, with or without holding down
 the SHIFT key.<br /></p>
</body>
</html>

How can I differentiate capital A from lowercase a in onkeydown event handler method? Above algorithm fires the same keyCode value. I need to detect the capital letters when they are pressed in onkeydown.

Note: The code contains an exception for SHIFT key. Otherwise it does not allow to type capital letters. BTW, I need to use onkeydown for my trial.

  • 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-15T11:18:04+00:00Added an answer on May 15, 2026 at 11:18 am

    It looks to me like you answered your own question. If you are detecting the SHIFT key, you can easily differentiate between capital and lowercase:

    if(e.shiftKey){
       alert("You pressed a CAPITAL letter with the code " + e.keyCode);
    }else{
       alert("You pressed a LOWERCASE letter with the code " + e.keyCode);
    }
    

    Or am I misunderstanding your question?

    Update: Upper case ASCII codes can easily be converted to lower case ASCII codes by adding 32, so all you need to do is this:

    <html>
    <head>
    <title>Test</title>
    
    <script type="text/javascript">
    
    function showChar(e){
      if(e.keyCode!=16){ // If the pressed key is anything other than SHIFT
            if(e.keyCode >= 65 && e.keyCode <= 90){ // If the key is a letter
                if(e.shiftKey){ // If the SHIFT key is down, return the ASCII code for the capital letter
                    alert("ASCII Code: "+e.keyCode);
                }else{ // If the SHIFT key is not down, convert to the ASCII code for the lowecase letter
                    alert("ASCII Code: "+(e.keyCode+32));
                }
            }else{
                alert("ASCII Code (non-letter): "+e.keyCode);
            }
      }
    }
    
    </script>
    </head>
    
    <body onkeydown="showChar(event);">
    <p>Press any character key, with or without holding down
     the SHIFT key.<br /></p>
    </body>
    </html>
    

    Update 2: Try this:

    <html>
    <head>
    <title>Test</title>
    
    <script type="text/javascript">
    
    function showChar(e){
      if(e.keyCode!=16){ // If the pressed key is anything other than SHIFT
            c = String.fromCharCode(e.keyCode);
            if(e.shiftKey){ // If the SHIFT key is down, return the ASCII code for the capital letter
                alert("ASCII Code: "+e.keyCode+" Character: "+c);
            }else{ // If the SHIFT key is not down, convert to the ASCII code for the lowecase letter
                c = c.toLowerCase(c);
                alert("ASCII Code: "+c.charCodeAt(0)+" Character: "+c);
            }
      }
    }
    
    </script>
    </head>
    
    <body onkeydown="showChar(event);">
    <p>Press any character key, with or without holding down
     the SHIFT key.<br /></p>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look at this html: <head> <title>Test page</title> <script type=text/javascript> function submitForm() {
Sample code: <!DOCTYPE html> <html> <head> <title>test</title> <script language=javascript type=text/javascript> function init() { var
function msg ($msg) { echo <script type='text/javascript'>alert('$msg');</script>; } if (count($_POST)) { msg('TEST!!!!!'); } <!DOCTYPE
This is my markup: <!DOCTYPE HTML> <html> <head> <title>Test title</title> <style type=text/css> * {
I have some HTML Code: <html> <head> <title>css test</title> <style type=text/css> .box{width:100%;float:left;background:red} </style> </head>
<head> <title>Overlay test</title> <meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 /> <style type=text/css> #overlay { position: absolute;
Basicily i have a index.html shown below.. <html> <head> <title>UI Test: Main Menu</title> <script
HTML: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8> <title></title> <link type=text/css href=galerina.css rel=stylesheet/> </head> <body>
Edit: Entire page (HTML) <!doctype html> <html> <head> <meta charset=utf-8 /> <title>jQuery Ajax Test</title>
Let's have a look at this HTML code: <!DOCTYPE html> <html> <head> <title>Test</title> </head>

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.