Close Menu
geekfence.comgeekfence.com
    What's Hot

    ClickFix attackers using new tactic to evade detection, says Microsoft – Computerworld

    March 7, 2026

    M&A Monthly: February/March 2026

    March 7, 2026

    Posit AI Blog: luz 0.4.0

    March 7, 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 Read2 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

    Stop Paving the Cowpath: Why Agentic-First Is the Only Way to Build for the Enterprise

    March 7, 2026

    Voice Content and Usability – A List Apart

    March 6, 2026

    How to Play Grand Poo World 3

    March 5, 2026

    Humans and Agents in Software Engineering Loops

    March 4, 2026

    Tips on How to Hire .NET Developers in Poland

    March 1, 2026

    MCP leaves much to be desired when it comes to data privacy and security

    February 28, 2026
    Top Posts

    Hard-braking events as indicators of road segment crash risk

    January 14, 202619 Views

    Understanding U-Net Architecture in Deep Learning

    November 25, 202518 Views

    How to integrate a graph database into your RAG pipeline

    February 8, 202610 Views
    Don't Miss

    ClickFix attackers using new tactic to evade detection, says Microsoft – Computerworld

    March 7, 2026

    “And all Windows computers should already be restricted so that random, unsigned (not signed by…

    M&A Monthly: February/March 2026

    March 7, 2026

    Posit AI Blog: luz 0.4.0

    March 7, 2026

    Top Reasons to Choose Precisely for SAP and Salesforce Process Automation

    March 7, 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

    ClickFix attackers using new tactic to evade detection, says Microsoft – Computerworld

    March 7, 2026

    M&A Monthly: February/March 2026

    March 7, 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.