Close Menu
geekfence.comgeekfence.com
    What's Hot

    Wealth management outlook for 2026: trends and sourcing implications 

    February 9, 2026

    T-Mobile US’ switching strategy lands in court again

    February 9, 2026

    Scientists create smart synthetic skin that can hide images and change shape

    February 9, 2026
    Facebook X (Twitter) Instagram
    • About Us
    • Contact Us
    Facebook Instagram
    geekfence.comgeekfence.com
    • Home
    • UK Tech News
    • AI
    • Big Data
    • Cyber Security
      • Cloud Computing
      • iOS Development
    • IoT
    • Mobile
    • Software
      • Software Development
      • Software Engineering
    • Technology
      • Green Technology
      • Nanotechnology
    • Telecom
    geekfence.comgeekfence.com
    Home»Software Development»Detect Caps Lock with JavaScript
    Software Development

    Detect Caps Lock with JavaScript

    AdminBy AdminJanuary 25, 2026No Comments2 Mins Read1 Views
    Facebook Twitter Pinterest LinkedIn Telegram Tumblr Email
    Detect Caps Lock with JavaScript
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Anyone is capable of having their caps lock key on at any given time without realizing so. Users can easily spot unwanted caps lock when typing in most inputs, but when using a password input, the problem isn’t so obvious. That leads to the user’s password being incorrect, which is an annoyance. Ideally developers could let the user know their caps lock key is activated.

    To detect if a user has their keyboard’s caps lock turn on, we’ll employ KeyboardEvent‘s getModifierState method:

    document.querySelector('input[type=password]').addEventListener('keyup', function (keyboardEvent) {
        const capsLockOn = keyboardEvent.getModifierState('CapsLock');
        if (capsLockOn) {
            // Warn the user that their caps lock is on?
        }
    });
    

    I’d never seen getModifierState used before, so I explored the W3C documentation to discover other useful values:

    dictionary EventModifierInit : UIEventInit {
      boolean ctrlKey = false;
      boolean shiftKey = false;
      boolean altKey = false;
      boolean metaKey = false;
    
      boolean modifierAltGraph = false;
      boolean modifierCapsLock = false;
      boolean modifierFn = false;
      boolean modifierFnLock = false;
      boolean modifierHyper = false;
      boolean modifierNumLock = false;
      boolean modifierScrollLock = false;
      boolean modifierSuper = false;
      boolean modifierSymbol = false;
      boolean modifierSymbolLock = false;
    };
    

    getModifierState provides a wealth of insight as to the user’s keyboard during key-centric events. I wish I had known about getModifier earlier in my career!

    Request Metrics real user monitoring
    Request Metrics real user monitoring
    Request Metrics real user monitoring
    Request Metrics real user monitoring
    • 5 More HTML5 APIs You Didn’t Know Existed

      5 More HTML5 APIs You Didn’t Know Existed

      The HTML5 revolution has provided us some awesome JavaScript and HTML APIs.  Some are APIs we knew we’ve needed for years, others are cutting edge mobile and desktop helpers.  Regardless of API strength or purpose, anything to help us better do our job is a…

    • CSS Filters

      CSS Filters

      CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let’s have…

    • Introducing MooTools Templated

      Introducing MooTools Templated

      One major problem with creating UI components with the MooTools JavaScript framework is that there isn’t a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating: new Element Madness The first way to create UI-driven…

    • Fancy FAQs with jQuery Sliders

      Fancy FAQs with jQuery Sliders

      Frequently asked questions can be super boring, right? They don’t have to be! I’ve already shown you how to create fancy FAQs with MooTools — here’s how to create the same effect using jQuery. The HTML Simply a series of H3s and DIVs wrapper…



    Source link
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    How to Sell UX Research with Two Simple Questions – A List Apart

    February 9, 2026

    Fixing Cumulative Layout Shift Problems on DavidWalshBlog

    February 8, 2026

    Context Engineering for Coding Agents

    February 7, 2026

    10 Best eCommerce CMS Compared by SCAND

    February 4, 2026

    Snowflake and OpenAI’s partnership, new insights in Google Play Console, and more — Daily News Digest

    February 3, 2026

    Breaking Out of the Box – A List Apart

    February 2, 2026
    Top Posts

    Hard-braking events as indicators of road segment crash risk

    January 14, 202617 Views

    Understanding U-Net Architecture in Deep Learning

    November 25, 202512 Views

    Achieving superior intent extraction through decomposition

    January 25, 20268 Views
    Don't Miss

    Wealth management outlook for 2026: trends and sourcing implications 

    February 9, 2026

    Global wealth management is entering a defining phase in 2025-2026 as firms scale their businesses…

    T-Mobile US’ switching strategy lands in court again

    February 9, 2026

    Scientists create smart synthetic skin that can hide images and change shape

    February 9, 2026

    AI Shows How Payment Delays Disrupt Your Business

    February 9, 2026
    Stay In Touch
    • Facebook
    • Instagram
    About Us

    At GeekFence, we are a team of tech-enthusiasts, industry watchers and content creators who believe that technology isn’t just about gadgets—it’s about how innovation transforms our lives, work and society. We’ve come together to build a place where readers, thinkers and industry insiders can converge to explore what’s next in tech.

    Our Picks

    Wealth management outlook for 2026: trends and sourcing implications 

    February 9, 2026

    T-Mobile US’ switching strategy lands in court again

    February 9, 2026

    Subscribe to Updates

    Please enable JavaScript in your browser to complete this form.
    Loading
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    © 2026 Geekfence.All Rigt Reserved.

    Type above and press Enter to search. Press Esc to cancel.