Close Menu
geekfence.comgeekfence.com
    What's Hot

    Open Cosmos launches first satellites for new LEO constellation

    January 25, 2026

    Achieving superior intent extraction through decomposition

    January 25, 2026

    How UX Research Reveals Hidden AI Orchestration Failures

    January 25, 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 Read0 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

    Fragments: January 8

    January 24, 2026

    How to Build and Optimize It for Success

    January 21, 2026

    Report: Companies with technical debt unlikely to see benefits from AI adoption

    January 20, 2026

    Is It Time for a Rethink? – A List Apart

    January 19, 2026

    I’m So Old: Web Edition

    January 18, 2026

    Stop Picking Sides

    January 17, 2026
    Top Posts

    Understanding U-Net Architecture in Deep Learning

    November 25, 202511 Views

    Hard-braking events as indicators of road segment crash risk

    January 14, 20269 Views

    Microsoft 365 Copilot now enables you to build apps and workflows

    October 29, 20258 Views
    Don't Miss

    Open Cosmos launches first satellites for new LEO constellation

    January 25, 2026

    Press Release Open Cosmos, the company building satellites to understand and connect the world, has…

    Achieving superior intent extraction through decomposition

    January 25, 2026

    How UX Research Reveals Hidden AI Orchestration Failures

    January 25, 2026

    ByteDance steps up its push into enterprise cloud services

    January 25, 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

    Open Cosmos launches first satellites for new LEO constellation

    January 25, 2026

    Achieving superior intent extraction through decomposition

    January 25, 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.