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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:41:57+00:00 2026-06-07T11:41:57+00:00

Is there any way to determine in javascript whether shift key is pressed on

  • 0

Is there any way to determine in javascript whether shift key is pressed on mobile keyboard, and distinguish it from the caps lock(twice pressed shift key)

  • 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-07T11:41:59+00:00Added an answer on June 7, 2026 at 11:41 am

    Some Facts

    First, let’s look at some facts about iOS keyboards I assume you already know:

    • When you enter the keyboard mode, the shift key is always activated
    • Caps Lock must be activated manually (I guess this is not used too widely)

    iPhone Shift Key Handling

    I investigated a bit into this issue, and here’s what I found:

    • The shift Key triggers no key Event

    • There is no special iPhone Browser API to detect whether the shift key is pressed or not, except in an iOS App (duh)

    • The keydown, keypress, keyup event triggered by iOS look normal, except they do not indicate shiftKey usage, and apart from their timestamp and type cannot be distinguished.

    • You cannot manually dispatch a Keyboard Event in iOS because of this issue, keyCode and which are readonly and always set to 0. Retriggering a Keyboard event to get some indication about the shift key still being on is impossible.

    • Actually, The iPhone treats the shift key like some sort of Short Term Caps Lock key. The difference is that normally, you activate it once, and it deactivates automatically.

    What can be done

    I assume you want to indicate on an input field whether the user should be careful about having Shift/Caps Lock pressed (a password field, for example). What I came up with is some sort of a workaround, but I think it’s better than nothing.

    You can also test the jsfiddle here.

    DOM Setup

    <div id="wrapper">
      <label for="test">ENTER SOMETHING HERE</label>
      <input type="text" name="test" id="test"/>
    </div>
    <div id="warning"></div>​
    

    Javascript

    This checks wheter the user did enter capitalized input, and it assumes the user is using caps lock if two capitalized letters where entered.

    var isCaps = false,
    isUppercase = false,
    str = '',
    test = document.getElementById('test'),
    warning = document.getElementById('warning');
    
    function capsDetection(e) {
    
        // Since where on iOS, we at least don't have to care 
        // about cross-browser stuff
        var s = String.fromCharCode(e.which);
        isCaps = isUppercase;
    
        // if the char doesn't match its lower case friend, and the shift key is 
        // not pressed (which is always the case on iOS, but we leave it there 
        // for readability), we have uppercase input
        isUppercase = (s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey);
    
        // if its the second uppercase input in a row, we may have caps lock input
        isCaps = isCaps && isUppercase;
    
        // set the warning
        if (isUppercase && !isCaps) {
            str = 'You where using the shift key';
        }
        else if (isCaps) {
            str = 'Caps lock seems to be activated';
        } else {
            str = '';
        }
        warning.innerHTML = str;
    }
    
    // the right event properties are only available on keypress
    test.addEventListener('keypress', capsDetection);
    

    As I said, better than nothing, but not a solution if you need to know the shift key is pressed without the user doing any input. That seems to be impossible right now.

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

Sidebar

Related Questions

Is there a cross-browser way from a Javascript event handler to determine whether the
Possible Duplicate: Is there any way to determine text direction from CultureInfo in asp.net?
Is there any way in Oracle to determine whether a package has state or
Is there any way to determine in Javascript if an object was created using
I want to know is there any way in JavaScript to determine height of
Is there a way in javascript to determine the return type(if any) of a
Is there any way to determine the pixel length of a string in jQuery/JavaScript?
Is there a RESTful way to determine whether a POST (or any other non-idempotent
Is there any way to determine if process was invoked by current application? I'm
Is there any way to determine when actual items are added to an ICollection<>

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.