Determining caps lock state

Discussion in 'Javascript' started by Robert, Oct 27, 2005.

  1. Robert

    Robert Guest

    Hi!

    I was wondering if the was any way to determine the state of the caps
    lock key, on or off.
    Of course I can capture the key events and see whether the caps lock is
    pressed, but that does not help.

    I have seen some example that looks at the characters entered in an
    input field to determine if the caps lock is on, but I was wondering if
    something is possible that is a bit more immediate to report the caps
    lock state.

    Robert.
    Robert, Oct 27, 2005
    #1
    1. Advertising

  2. Robert

    rf Guest

    Robert wrote:

    > Hi!
    >
    > I was wondering if the was any way to determine the state of the caps
    > lock key, on or off.
    > Of course I can capture the key events and see whether the caps lock is
    > pressed, but that does not help.
    >
    > I have seen some example that looks at the characters entered in an
    > input field to determine if the caps lock is on, but I was wondering if
    > something is possible that is a bit more immediate to report the caps
    > lock state.


    Why?

    --
    Cheers
    Richard.
    rf, Oct 27, 2005
    #2
    1. Advertising

  3. Robert

    Robert Guest

    rf wrote:
    > Robert wrote:
    >
    >
    >>Hi!
    >>
    >>I was wondering if the was any way to determine the state of the caps
    >>lock key, on or off.

    >
    > Why?


    It is to alert that the caps lock is enabled on a form where a user can
    change his password. I want to make a block visible when the caps lock
    is enabled and hide it again when it is off.
    I prefer to do it as similar as we do in a swing client.
    Robert, Oct 27, 2005
    #3
  4. Robert

    rf Guest

    Robert wrote:

    > rf wrote:
    >> Robert wrote:
    >>
    >>>Hi!
    >>>
    >>>I was wondering if the was any way to determine the state of the caps
    >>>lock key, on or off.

    >>
    >> Why?

    >
    > It is to alert that the caps lock is enabled


    I have a little light on my keyboard that indicates my caps lock status.

    > on a form where a user can
    > change his password.


    Password fields should be, well, type="password" fields.

    > I want to make a block visible when the caps lock
    > is enabled and hide it again when it is off.


    You are trying to change the behaviour of my browser. Don't. How do you
    know I even *have* a caps lock button?

    > I prefer to do it as similar as we do in a swing client.


    What is a "swing client"?

    --
    Cheers
    Richard.
    rf, Oct 27, 2005
    #4
  5. Robert

    Evertjan. Guest

    Robert wrote on 27 okt 2005 in comp.lang.javascript:

    > rf wrote:
    >> Robert wrote:
    >>>I was wondering if the was any way to determine the state of the caps
    >>>lock key, on or off.

    >>
    >> Why?

    >
    > It is to alert that the caps lock is enabled on a form where a user can
    > change his password. I want to make a block visible when the caps lock
    > is enabled and hide it again when it is off.
    > I prefer to do it as similar as we do in a swing client.


    Better make the serverside password parsing caseinsensitive,

    jscript-ASP:

    password = request.form('password').toLowerCase();

    or even better [securitywize] "case reversed" serverside,
    and allow testing for both password and password2:

    jscript-ASP:

    password = request.form('password');
    password2 = '';
    for (i=0;i<password.length;i++){
    l = password.charAt(i);
    password2 +=
    (l==l.toLowerCase())
    ?l.toUpperCase():l.toLowerCase();
    };

    [can this be done by regex, I wonder?]

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Oct 27, 2005
    #5
  6. Robert wrote:

    > Hi!
    >
    > I was wondering if the was any way to determine the state of the caps
    > lock key, on or off.
    > Of course I can capture the key events and see whether the caps lock is
    > pressed, but that does not help.
    >
    > I have seen some example that looks at the characters entered in an
    > input field to determine if the caps lock is on, but I was wondering if
    > something is possible that is a bit more immediate to report the caps
    > lock state.
    >
    > Robert.


    I don't think you can do it within Javascript alone. Even Visual Basic
    has to use an external user32.dll to get the caps lock state.

    Here is a site with some kind of suggestion:-

    http://www.howtocreate.co.uk/jslibs/htmlhigh/capsDetect.html

    Can't vouch for it though.

    Julian
    Julian Turner, Oct 27, 2005
    #6
  7. Robert

    Robert Guest

    rf wrote:
    > Robert wrote:
    >
    >>>>I was wondering if the was any way to determine the state of the caps
    >>>>lock key, on or off.
    >>>
    >>>Why?

    >>
    >>It is to alert that the caps lock is enabled

    >
    >
    > I have a little light on my keyboard that indicates my caps lock status.


    lol
    Well it is neither for me or you. You should know how many regular users
    have had problems with caps-lock and passwords.

    >>on a form where a user can
    >>change his password.

    >
    >
    > Password fields should be, well, type="password" fields.


    Uhmmm... yes of course. If they were type="text" then they could see
    their uppercase characters and I would not ask for a caps-lock indication.

    >>I want to make a block visible when the caps lock
    >>is enabled and hide it again when it is off.

    >
    >
    > You are trying to change the behaviour of my browser. Don't.


    I am not changing the behaviour of your browser.
    Does the caps-lock indication in a 'normal' windows application change
    your operating system?

    > How do you
    > know I even *have* a caps lock button?


    Well if you don't have it then you will never see the indicator.

    >>I prefer to do it as similar as we do in a swing client.

    >
    >
    > What is a "swing client"?


    Sorry. I meant a Java application that uses Swing components.
    Robert, Oct 28, 2005
    #7
  8. Robert

    Robert Guest

    Evertjan. wrote:
    > Robert wrote on 27 okt 2005 in comp.lang.javascript:
    >
    >
    >>rf wrote:
    >>
    >>>Robert wrote:
    >>>
    >>>>I was wondering if the was any way to determine the state of the caps
    >>>>lock key, on or off.
    >>>

    > Better make the serverside password parsing caseinsensitive,


    I would do that if I were responsible for the serverside.
    Just busy making a webclient that resembles the Java swing client as
    best what is possible.

    > jscript-ASP:


    I use Apache Tapestry :)
    Robert, Oct 28, 2005
    #8
  9. Robert

    Robert Guest

    Julian Turner wrote:
    > Robert wrote:
    >
    >
    >>Hi!
    >>
    >>I was wondering if the was any way to determine the state of the caps
    >>lock key, on or off.

    >
    > I don't think you can do it within Javascript alone. Even Visual Basic
    > has to use an external user32.dll to get the caps lock state.
    >
    > Here is a site with some kind of suggestion:-
    >
    > http://www.howtocreate.co.uk/jslibs/htmlhigh/capsDetect.html


    I found that already. The 'problem' with this is that the indicator
    would only change when actually inside the input field and pressing a
    character. Nothing would change by just pressing the caps-lock.

    Anyway I have an idea now how it might be possible. If I succeed I will
    post it on Monday.
    Robert, Oct 28, 2005
    #9
  10. Robert

    Evertjan. Guest

    Robert wrote on 28 okt 2005 in comp.lang.javascript:

    >> jscript-ASP:

    >
    > I use Apache Tapestry :)


    The latter is off topic.


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Oct 28, 2005
    #10
  11. Robert

    Evertjan. Guest

    Robert wrote on 28 okt 2005 in comp.lang.javascript:
    > I would do that if I were responsible for the serverside.


    <input type='password'
    onblur='this.value=this.value.toLowerCase();'>

    will do clientside, but you have to convince all users that haven't
    all lowecase pwds to change them.

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Oct 28, 2005
    #11
  12. Robert

    VK Guest

    > Determining caps lock state

    I may be missing some extra issue here, but where is the problem?
    CapsLock Unicode value is 20
    So just monitor it via keyDown or keyUp (not keyPress!)

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <script type="text/javascript">
    function init() {
    document.onkeydown = test;
    }

    function test(e){
    if (e) {
    alert(e.which);
    }
    else {
    alert(event.keyCode);
    }
    }
    window.onload = init;
    </script>
    </head>

    <body bgcolor="#FFFFFF">

    </body>
    </html>
    VK, Oct 28, 2005
    #12
  13. Robert

    Randy Webb Guest

    VK said the following on 10/28/2005 8:48 AM:
    >>Determining caps lock state

    >
    >
    > I may be missing some extra issue here, but where is the problem?
    > CapsLock Unicode value is 20
    > So just monitor it via keyDown or keyUp (not keyPress!)
    >
    > <html>
    > <head>
    > <title>Untitled Document</title>
    > <meta http-equiv="Content-Type" content="text/html;
    > charset=iso-8859-1">
    > <script type="text/javascript">
    > function init() {
    > document.onkeydown = test;
    > }
    >
    > function test(e){
    > if (e) {
    > alert(e.which);
    > }
    > else {
    > alert(event.keyCode);
    > }
    > }
    > window.onload = init;
    > </script>
    > </head>
    >
    > <body bgcolor="#FFFFFF">
    >
    > </body>
    > </html>
    >


    Because that does not tell you the state it is in. Only if the key was
    pressed.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Randy Webb, Oct 28, 2005
    #13
  14. Robert

    Robert Guest

    Evertjan. wrote:
    > Robert wrote on 28 okt 2005 in comp.lang.javascript:
    >
    >>I would do that if I were responsible for the serverside.

    >
    >
    > <input type='password'
    > onblur='this.value=this.value.toLowerCase();'>
    >
    > will do clientside, but you have to convince all users that haven't
    > all lowecase pwds to change them.
    >


    Thanks, but it really is not an option.
    Robert, Oct 28, 2005
    #14
  15. Robert

    Robert Guest

    Evertjan. wrote:
    > Robert wrote on 28 okt 2005 in comp.lang.javascript:
    >
    >
    >>>jscript-ASP:

    >>
    >>I use Apache Tapestry :)

    >
    >
    > The latter is off topic.
    >
    >


    I know... just for your information.
    Anyway, neither Tapestry or javascript would have been the correct place
    to implement lowercase password. Because that would not help those
    changing passwords with their Java Swing application.
    But all of this is getting off-topic.
    Robert, Oct 28, 2005
    #15
  16. Robert

    BootNic Guest

    > "Robert" <> wrote:
    > news:4360cc35$0$11079$4all.nl....
    >
    > Hi!
    >
    > I was wondering if the was any way to determine the state of the
    > caps lock key, on or off.
    > Of course I can capture the key events and see whether the caps
    > lock is pressed, but that does not help.
    >
    > I have seen some example that looks at the characters entered in an
    > input field to determine if the caps lock is on, but I was
    > wondering if something is possible that is a bit more immediate to
    > report the caps lock state.
    >
    > Robert.


    http://www.howtocreate.co.uk/jslibs/otherdemo.html#cld

    --
    BootNic Friday, October 28, 2005 9:01 PM

    I try to take one day at a time, but sometimes several days attack me at once.
    *Jennifer Unlimited*
    BootNic, Oct 29, 2005
    #16
  17. Robert

    Robert Guest

    BootNic wrote:
    >>"Robert" <> wrote:
    >>news:4360cc35$0$11079$4all.nl....
    >>
    >>I have seen some example that looks at the characters entered in an
    >>input field to determine if the caps lock is on, but I was
    >>wondering if something is possible that is a bit more immediate to
    >>report the caps lock state.
    >>
    >>Robert.

    >
    >
    > http://www.howtocreate.co.uk/jslibs/otherdemo.html#cld


    Thanks, but like I said I know about this already.
    I was looking for something better.
    Robert, Oct 29, 2005
    #17
  18. Robert

    VK Guest

    Robert wrote:
    > >>I have seen some example that looks at the characters entered in an
    > >>input field to determine if the caps lock is on, but I was
    > >>wondering if something is possible that is a bit more immediate to
    > >>report the caps lock state.


    There must be somewhere a pre-historic keysta32.ocx control for Windows
    95 (CLASSID="clsid:B9D22270-0C24-101B-AEBD-04021C009402"). It gave you
    Num Lock, Caps Lock and Scroll Lock states. You may try to find it and
    see if it still works on current Windows dll's.

    JavaScript / JScript by themselve have nothing to propose on this
    matter within the chosen approach.
    VK, Oct 30, 2005
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fuzzyman
    Replies:
    3
    Views:
    476
    Andrew MacIntyre
    Dec 5, 2003
  2. Robert Brewer
    Replies:
    0
    Views:
    478
    Robert Brewer
    Dec 5, 2003
  3. k3xji
    Replies:
    7
    Views:
    785
    Gabriel Genellina
    Dec 30, 2008
  4. N3wCr4Zy

    Caps Lock State on Windows

    N3wCr4Zy, Dec 11, 2009, in forum: Python
    Replies:
    2
    Views:
    1,354
    Gabriel Genellina
    Dec 12, 2009
  5. katera
    Replies:
    9
    Views:
    428
    John W. Kennedy
    Apr 9, 2007
Loading...

Share This Page