Re: caps lock state

Dave Tapuska <[email protected]> Mon, 14 Dec 2015 15:08:11 -0500
Newsgroups gmane.comp.web.dom.general
Message-ID <CAHXv1wnAGsXOs522m-H630=3YppEo5i34dU2MaLN1re0MhhUEg@mail.gmail.com>
--94eb2c07efa68441110526e13bba
Content-Type: text/plain; charset=UTF-8

Check out
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState

It should be supported or at least in Chrome's case is making its way
through the release channels.

dave.

On Mon, Dec 14, 2015 at 3:00 PM, Rob Garrison <[email protected]> wrote:

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

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

<div dir=3D"ltr">Check out=C2=A0<a href=3D"https://developer.mozilla.org/en=
-US/docs/Web/API/KeyboardEvent/getModifierState">https://developer.mozilla.=
org/en-US/docs/Web/API/KeyboardEvent/getModifierState</a><div><br></div><di=
v>It should be supported or at least in Chrome&#39;s case is making its way=
 through the release channels.</div><div><br></div><div>dave.</div></div><d=
iv class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Mon, Dec 14, 201=
5 at 3:00 PM, Rob Garrison <span dir=3D"ltr">&lt;<a href=3D"mailto:wowmotty=
@gmail.com" target=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
 #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div style=3D"font-size:12.8=
px">Hi!</div><div style=3D"font-size:12.8px"><br></div><div style=3D"font-s=
ize:12.8px">There is no way to determine the actual state of a caps lock ke=
y. I would like</div><div style=3D"font-size:12.8px">to request an enhancem=
ent of the event object to include the caps lock state:</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.addEventListener( &#39;keydown&#39;, f=
unction( event ) {</div><div style=3D"font-size:12.8px">=C2=A0 if ( event.c=
apsLock ) {</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><d=
iv 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.8=
px">This basic method targets the &quot;a&quot; through &quot;z&quot; and c=
apital &quot;A&quot; through &quot;Z&quot;</div><div style=3D"font-size:12.=
8px">characters to make a comparison. 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 keyboards,</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 `eve=
nt.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-siz=
e:12.8px">document.addEventListener( &#39;keypress&#39;, function( event ) =
{</div><div style=3D"font-size:12.8px">=C2=A0 var k =3D event.charCode;</di=
v><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.8px">=C2=A0 =C2=A0 =C2=A0 =C2=A0// ASCII lowercas=
e 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 a=
lert( &#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"f=
ont-size:12.8px">I know modern keyboards are starting to replace the caps l=
ock key with a</div><div style=3D"font-size:12.8px">control key, but I thin=
k this would still be a useful addition.</div><div style=3D"font-size:12.8p=
x"><br></div><div style=3D"font-size:12.8px">Thanks for your attention.</di=
v></div>
</blockquote></div><br></div>

--94eb2c07efa68441110526e13bba--