I have partly stolen, and partly adjusted and perfected this little JavaScript code snippet to check if caps lock is on, and displays a message if it is:
var capsLockOnMessageDisplayed = false;
function checkCapsLock( e )
{
var keyCode = 0;
var shiftKeyOn = false;
if ( document.all )
{
keyCode = e.keyCode;
shiftKeyOn = e.shiftKey;
}
else if ( document.layers )
{
keyCode=e.which;
shiftKeyOn = ( keyCode == 16 ) ? true : false;
}
else if ( document.getElementById )
{
keyCode = e.which;
shiftKeyOn = ( keyCode == 16 ) ? true : false;
}
if ( ( keyCode >= 65 && keyCode <= 90 ) && !shiftKeyOn ) { displayMessage(); } else if ( ( keyCode >= 97 && keyCode <= 122 ) & shiftKeyOn ) { displayMessage(); } } function displayMessage() { if( !capsLockOnMessageDisplayed ) { alert( 'Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.' ); capsLockOnMessageDisplayed = true; } }
Ps. check this out: CAPSoff
No comments:
Post a Comment