Andy Brook

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromAndy Brook
ToMe
Subjectgreetings
Date19 February 2004 15:23
Im using your caps lock detector, great, but through the provided source
allowed support for an 'on' method, it didn't for 'off'.  Ive extended
it to always call a capsLockOff() method so I can do div-hiding etc.
 
Minor change but there you go!
 
 
function capsDetect( e ) {
      if( !e )
      { 
            e = window.event;
      }

      if( !e )
      {
            capsLockOff();
            return;
      }

      //what (case sensitive in good browsers) key was pressed
      var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode :
        ( e.charCode ? e.charCode : 0 ) );

      //was the shift key was pressed
      var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) );
      //bitWise AND

      //if upper case, check if shift is not pressed. if lower case,
      //check if shift is pressed
      if( ( theKey > 64 && theKey < 91 && !theShift ) ||
        ( theKey > 96 && theKey < 123 && theShift ) )
      {
            if( typeof( capsError ) == 'string' )
            {
                  alert( capsError );
            }
            else
            {
                  capsLockOn();
            }
      }
      else
      {
            capsLockOff();
      }
}

Cheers,
Andy.
FromMe
ToAndy Brook
SubjectRe: caps lock detect script
Date19 February 2004 15:39
nice idea. I will add this functionality into the next release (later today)
FromMe
ToAndy Brook
SubjectRe: caps lock detect script
Date19 February 2004 23:06
I have now made the change. it's a little bit different to your
implementation, because it basically runs the function every time a key is
pressed, but it now passes the funtion a boolean true/false to say if caps
lock is engaged.

hope you find it useful

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.