caps lock state

Rob Garrison <[email protected]> Mon, 14 Dec 2015 14:00:46 -0600
Newsgroups gmane.comp.web.dom.general
Message-ID <CAKOB1kRXw5nyz4diUwvBb=umxENst77u9wa=NKFVKXF2z8aSRA@mail.gmail.com>
--001a11438baaf734e30526e12055
Content-Type: text/plain; charset=UTF-8

Hi!

There is no way to determine the actual state of a caps lock key. I would
like
to request an enhancement of the event object to include the caps lock
state:

```js
document.addEventListener( 'keydown', function( event ) {
  if ( event.capsLock ) {
    alert( 'caps lock on!' );
  }
});
```

This basic method targets the "a" through "z" and capital "A" through "Z"
characters to make a comparison. This method does not include accented
characters that would be available on non-U.S. or international keyboards,
and it can only be used during a "keypress" event. "keypress" is the
only event in which `event.charCode` returns accurate values.

```js
document.addEventListener( 'keypress', function( event ) {
  var k = event.charCode;
  // ASCII uppercase A = 65; ascii uppercase Z = 90
  if ( ( ( k >= 65 && k <= 90 ) && !event.shiftKey ) ||
       // ASCII lowercase a = 97; ASCII lowercase z = 122
       ( ( k >= 97 && k <= 122) && e.shiftKey ) ) {
    alert( 'caps lock on!' );
  }
});
```

I know modern keyboards are starting to replace the caps lock key with a
control key, but I think this would still be a useful addition.

Thanks for your attention.

--001a11438baaf734e30526e12055
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div style=3D"font-size:12.8px">Hi!</div><div style=3D"fon=
t-size:12.8px"><br></div><div style=3D"font-size:12.8px">There is no way to=
 determine the actual state of a caps lock key. I would like</div><div styl=
e=3D"font-size:12.8px">to request an enhancement of the event object to inc=
lude the caps lock state:</div><div style=3D"font-size:12.8px"><br></div><d=
iv style=3D"font-size:12.8px">```js</div><div style=3D"font-size:12.8px">do=
cument.addEventListener( &#39;keydown&#39;, function( event ) {</div><div s=
tyle=3D"font-size:12.8px">=C2=A0 if ( event.capsLock ) {</div><div style=3D=
"font-size:12.8px">=C2=A0 =C2=A0 alert( &#39;caps lock on!&#39; );</div><di=
v style=3D"font-size:12.8px">=C2=A0 }</div><div style=3D"font-size:12.8px">=
});</div><div style=3D"font-size:12.8px">```</div><div style=3D"font-size:1=
2.8px"><br></div><div style=3D"font-size:12.8px">This basic method targets =
the &quot;a&quot; through &quot;z&quot; and capital &quot;A&quot; through &=
quot;Z&quot;</div><div style=3D"font-size:12.8px">characters to make a comp=
arison. This method does not include accented</div><div style=3D"font-size:=
12.8px">characters that would be available on non-U.S. or international key=
boards,</div><div style=3D"font-size:12.8px">and it can only be used during=
 a &quot;keypress&quot; event. &quot;keypress&quot; is the</div><div style=
=3D"font-size:12.8px">only event in which `event.charCode` returns accurate=
 values.</div><div style=3D"font-size:12.8px"><br></div><div style=3D"font-=
size:12.8px">```js</div><div style=3D"font-size:12.8px">document.addEventLi=
stener( &#39;keypress&#39;, function( event ) {</div><div style=3D"font-siz=
e:12.8px">=C2=A0 var k =3D event.charCode;</div><div style=3D"font-size:12.=
8px">=C2=A0 // ASCII uppercase A =3D 65; ascii uppercase Z =3D 90</div><div=
 style=3D"font-size:12.8px">=C2=A0 if ( ( ( k &gt;=3D 65 &amp;&amp; k &lt;=
=3D 90 ) &amp;&amp; !event.shiftKey ) ||</div><div style=3D"font-size:12.8p=
x">=C2=A0 =C2=A0 =C2=A0 =C2=A0// ASCII lowercase a =3D 97; ASCII lowercase =
z =3D 122</div><div style=3D"font-size:12.8px">=C2=A0 =C2=A0 =C2=A0 =C2=A0(=
 ( k &gt;=3D 97 &amp;&amp; k &lt;=3D 122) &amp;&amp; e.shiftKey ) ) {</div>=
<div style=3D"font-size:12.8px">=C2=A0 =C2=A0 alert( &#39;caps lock on!&#39=
; );</div><div style=3D"font-size:12.8px">=C2=A0 }</div><div style=3D"font-=
size:12.8px">});</div><div style=3D"font-size:12.8px">```</div><div style=
=3D"font-size:12.8px"><br></div><div style=3D"font-size:12.8px">I know mode=
rn keyboards are starting to replace the caps lock key with a</div><div sty=
le=3D"font-size:12.8px">control key, but I think this would still be a usef=
ul addition.</div><div style=3D"font-size:12.8px"><br></div><div style=3D"f=
ont-size:12.8px">Thanks for your attention.</div></div>

--001a11438baaf734e30526e12055--