Email conversation
From | Andy Brook |
To | Me |
Subject | greetings |
Date | 19 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.
From | Me |
To | Andy Brook |
Subject | Re: caps lock detect script |
Date | 19 February 2004 15:39 |
nice idea. I will add this functionality into the next release (later today)
From | Me |
To | Andy Brook |
Subject | Re: caps lock detect script |
Date | 19 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/