Friday, November 10, 2006

I fucking hate caps lock

I hate it when it happens: You're typing your user name and password, but it doesn't work. Then you do it again, and it doesn't work.. Then you do it AGAIN, and it doesn't work. Then you look at the little Logitech stand for your wireless desktop and realize caps lock is on !!!!

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: