{"id":2767,"date":"2025-05-23T19:30:57","date_gmt":"2025-05-23T19:30:57","guid":{"rendered":"https:\/\/techtrendfeed.com\/?p=2767"},"modified":"2025-05-23T19:30:57","modified_gmt":"2025-05-23T19:30:57","slug":"detect-caps-lock-with-javascript","status":"publish","type":"post","link":"https:\/\/techtrendfeed.com\/?p=2767","title":{"rendered":"Detect Caps Lock with JavaScript"},"content":{"rendered":" \r\n<br><div id=\"main\"><article itemscope=\"\" itemtype=\"http:\/\/schema.org\/Article\">\n<p>Anybody is able to having their caps lock key on at any given time with out realizing so.  Customers can simply spot undesirable caps lock when typing in most inputs, however when utilizing a <code>password<\/code> <code>enter<\/code>, the issue is not so apparent.  That results in the person&#8217;s password being incorrect, which is an annoyance.  Ideally builders may let the person know their caps lock secret is activated.<\/p>\n\n\n\n<p>To detect if a person has their keyboard&#8217;s caps lock activate, we&#8217;ll make use of <code>KeyboardEvent<\/code>&#8216;s <code>getModifierState<\/code> technique:<\/p>\n\n\n\n<pre class=\"js\">\ndoc.querySelector('enter[type=password]').addEventListener('keyup', perform (keyboardEvent) {\n    const capsLockOn = keyboardEvent.getModifierState('CapsLock');\n    if (capsLockOn) {\n        \/\/ Warn the person that their caps lock is on?\n    }\n});\n<\/pre>\n\n\n\n<p>I would by no means seen <code>getModifierState<\/code> used earlier than, so I explored the <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/w3c.github.io\/uievents\/#event-modifier-initializers\">W3C documentation<\/a> to find different helpful values:<\/p>\n\n\n\n<pre class=\"text\">\ndictionary EventModifierInit : UIEventInit {\n  boolean ctrlKey = false;\n  boolean shiftKey = false;\n  boolean altKey = false;\n  boolean metaKey = false;\n\n  boolean modifierAltGraph = false;\n  boolean modifierCapsLock = false;\n  boolean modifierFn = false;\n  boolean modifierFnLock = false;\n  boolean modifierHyper = false;\n  boolean modifierNumLock = false;\n  boolean modifierScrollLock = false;\n  boolean modifierSuper = false;\n  boolean modifierSymbol = false;\n  boolean modifierSymbolLock = false;\n};\n<\/pre>\n\n\n\n<p><code>getModifierState<\/code> supplies a wealth of perception as to the person&#8217;s keyboard throughout key-centric occasions.  I want I had identified about <code>getModifier<\/code> earlier in my profession!<\/p>\n\n\n\n<div class=\"x x-long x-secondary\">\n    \n    \n    <div class=\"x-secondary-large\">\n    <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/requestmetrics.com\/?utm_source=davidwalsh\" style=\"display:block;\">\n        <img decoding=\"async\" src=\"https:\/\/davidwalsh.name\/demo\/rm_perf_banner-728.min.svg\" style=\"max-width:100%;height:auto;\" alt=\"Request Metrics real user monitoring\" loading=\"lazy\" width=\"728\" height=\"90\"\/>\n    <\/a>\n    <\/div>\n    <div class=\"x-secondary-small\">\n    <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/requestmetrics.com\/?utm_source=davidwalsh\" style=\"display:block;\">\n        <img decoding=\"async\" src=\"https:\/\/davidwalsh.name\/demo\/rm_perf_block_300.min.svg\" style=\"max-width:100%;height:auto;\" alt=\"Request Metrics real user monitoring\" loading=\"lazy\" width=\"300\" height=\"250\"\/>\n    <\/a>\n    <\/div>\n<\/div>\n\n\n\n\n\n<\/article>\n\n<div class=\"article-block\" style=\"min-height:90px\"><div class=\"x x-long x-terciary\" style=\"max-height: none;\">\n  \n    \n    \n<div class=\"x-secondary-large\">\n  <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/requestmetrics.com\/?utm_source=davidwalsh\" style=\"display:block;\">\n    <img decoding=\"async\" src=\"https:\/\/davidwalsh.name\/demo\/rm_perf_banner-728.min.svg\" style=\"max-width:100%;height:auto;\" alt=\"Request Metrics real user monitoring\" loading=\"lazy\" width=\"728\" height=\"90\"\/>\n  <\/a>\n<\/div>\n<div class=\"x-secondary-small\">\n  <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/requestmetrics.com\/?utm_source=davidwalsh\" style=\"display:block;\">\n    <img decoding=\"async\" src=\"https:\/\/davidwalsh.name\/demo\/rm_perf_block_300.min.svg\" style=\"max-width:100%;height:auto;\" alt=\"Request Metrics real user monitoring\" loading=\"lazy\" width=\"300\" height=\"250\"\/>\n  <\/a>\n<\/div>\n\n  \n\n<\/div>\n<\/div>\n\n\n<div class=\"article-block post-more\" style=\"\u201cclear:both;\u201d\"><ul class=\"post-list small-list\"><li data-url=\"https:\/\/davidwalsh.name\/fetch\" itemscope=\"\" itemtype=\"http:\/\/schema.org\/Article\"><span itemscope=\"\" itemtype=\"https:\/\/schema.org\/ImageObject\"><img decoding=\"async\" src=\"https:\/\/davidwalsh.name\/demo\/html5250.png?preview\" class=\"post-image\" alt=\"fetch API\"\/><\/span><div class=\"preview\"><h3 itemprop=\"name\"><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/davidwalsh.name\/fetch\" itemprop=\"url\">fetch\u00a0API<\/a><\/h3><p>One of many\u00a0worst stored secrets and techniques about AJAX on the internet is that the underlying API for it, <code>XMLHttpRequest<\/code>, wasn&#8217;t actually made for what we have been utilizing it for. \u00a0We have accomplished properly to\u00a0create elegant APIs round XHR however we all know we are able to do higher. \u00a0Our effort to&#8230;<\/p><\/div><\/li><li data-url=\"https:\/\/davidwalsh.name\/css-flip\" itemscope=\"\" itemtype=\"http:\/\/schema.org\/Article\"><span itemscope=\"\" itemtype=\"https:\/\/schema.org\/ImageObject\"><img decoding=\"async\" src=\"https:\/\/davidwalsh.name\/demo\/css-flip.png?preview\" class=\"post-image\" alt=\"Create a CSS Flipping Animation\"\/><\/span><div class=\"preview\"><h3 itemprop=\"name\"><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/davidwalsh.name\/css-flip\" itemprop=\"url\">Create a CSS Flipping\u00a0Animation<\/a><\/h3><p><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/davidwalsh.name\/demo\/css-flip.php\"\/>&#13;&#13;CSS animations are loads of enjoyable;  the fantastic thing about them is that by way of many easy properties, you possibly can create something from a sublime fade in to a WTF-Pixar-would-be-proud impact.  One CSS impact someplace in between is the CSS flip impact, whereby there&#8217;s&#8230;<\/p><\/div><\/li><\/ul><\/div><div class=\"article-block post-more\"><ul class=\"post-list small-list\"><li data-url=\"https:\/\/davidwalsh.name\/dojo-digg\" itemscope=\"\" itemtype=\"http:\/\/schema.org\/Article\"><span itemscope=\"\" itemtype=\"https:\/\/schema.org\/ImageObject\"><img decoding=\"async\" src=\"https:\/\/davidwalsh.name\/demo\/storylist-share.png?preview\" class=\"post-image\" alt=\"Digg-Style Dynamic Share Widget Using the Dojo Toolkit\"\/><\/span><div class=\"preview\"><h3 itemprop=\"name\"><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/davidwalsh.name\/dojo-digg\" itemprop=\"url\">Digg-Type Dynamic Share Widget Utilizing the Dojo\u00a0Toolkit<\/a><\/h3><p><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/davidwalsh.name\/demo\/dojo-digg-share.php\"\/>&#13;&#13;I&#8217;ve all the time seen Digg as a really progressive web site.  Digg makes use of experimental, ajaxified strategies for feedback and mission-critical capabilities.  One good contact Digg has added to their web site is their hover share widget.  Here is easy methods to implement that performance in your website&#8230;<\/p><\/div><\/li><li data-url=\"https:\/\/davidwalsh.name\/mootools-link-alert\" itemscope=\"\" itemtype=\"http:\/\/schema.org\/Article\"><span itemscope=\"\" itemtype=\"https:\/\/schema.org\/ImageObject\"><img decoding=\"async\" src=\"https:\/\/davidwalsh.name\/demo\/css3logo250.jpg?preview\" class=\"post-image\" alt=\"Introducing MooTools LinkAlert\"\/><\/span><div class=\"preview\"><h3 itemprop=\"name\"><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/davidwalsh.name\/mootools-link-alert\" itemprop=\"url\">Introducing MooTools\u00a0LinkAlert<\/a><\/h3><p>One in every of my favourite Firefox plugins is known as <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/3199\">LinkAlert<\/a>.  LinkAlert reveals the person an icon once they hover over a particular hyperlink, like a hyperlink to a Microsoft Phrase DOC or a PDF file.  I like that warning as a result of I hate the shock&#8230;<\/p><\/div><\/li><\/ul><\/div><\/div>\r\n<br>\r\n","protected":false},"excerpt":{"rendered":"<p>Anybody is able to having their caps lock key on at any given time with out realizing so. Customers can simply spot undesirable caps lock when typing in most inputs, however when utilizing a password enter, the issue is not so apparent. That results in the person&#8217;s password being incorrect, which is an annoyance. Ideally [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2769,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[2680,795,443,2101],"class_list":["post-2767","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-caps","tag-detect","tag-javascript","tag-lock"],"_links":{"self":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/2767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2767"}],"version-history":[{"count":1,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/2767\/revisions"}],"predecessor-version":[{"id":2768,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/2767\/revisions\/2768"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/media\/2769"}],"wp:attachment":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- This website is optimized by Airlift. Learn more: https://airlift.net. Template:. Learn more: https://airlift.net. Template: 69d9690a190636c2e0989534. Config Timestamp: 2026-04-10 21:18:02 UTC, Cached Timestamp: 2026-05-06 22:01:37 UTC -->