Skip to content

24 ways to impress your friends

Capturing Caps Lock


Comments are ordered by helpfulness, as indicated by you. Help us pick out the gems and discourage asshattery by voting on notable comments.

Got something to add? You can leave a comment below.

Albert Peschar

Hey, this should work for accented letters.

var char = string.fromCharCode(which);
if(char.toLowerCase() == char) var is_lower_case = true;
if(char.toUpperCase() == char) var is_upper_case = true;

Dustin Diaz

Nevermind that I could have figured this out on my own, but I sure as hell wouldn’t have thought of it… this is a genius usability enhancement to any password form! I can’t think of how many times I’ve retyped in a password over and over ‘thinking’ I’m typing it correctly, only to find out I had caplocks on.

Well done.

Martin S

It’s a great idea and works almost. My Safari 3 and Firefox reports the same keyCode when caps lock is on, no matter if shift is pressed or not. This makes the script works great if you don’t have Caps lock on and use shift at the same time.


A neat idea but falls down in some cases because of the assumption on the nature of keyboard operation. Some keyboards – definitely the iPhone and I suspect also assistive techniques such as Sticky Keys on Windows – let you type capitals without enabling caps lock or holding down shift so the assumption fails.

For the iPhone you could include an exception based on the user-agent. But clearly that won’t capture all such quirky keyboards.

James Henstridge

How well does this work for non-English locales? It looks like it won’t display the caps lock warning if the user enters an accented letter. I wonder what happens in non-latin locales?

Eivind Uggedal

I’ll guesstimate that 10-20% of casual users use caps lock for single characters in stead of shift when entering passwords after observing hundreds of university students enter their passwords working as first line support.


James: hand on heart, I’m not sure. I did consider the issue of non-English locales, but I don’t know enough about what happens if you capitalise a non-English letter. I’d love to hear commentary from people who know about this so that the script can correctly handle those characters!


shifted letters are lower-case if Caps Lock is on

As possibly mentioned above, this isn’t true on the Mac. I don’t think that matters though: I can’t imagine many people putting caps lock on, then holding down shift when they type letters.

Arthus Erea

Very cool and inventive technique. However, there has to be a way to do this without first requiring a user to enter a letter. Otherwise, a certain amount of nice functionality is lost.

For instance, whenever entering a password in Mac OS X and you have the Caps Lock key on a cool little up arrow shows up in the field. Is there a method of detecting before a user enters anything (and then applying some CSS class, etc.)

I know it is possible with IE, but I think it would be best to find some cross browser method.

Impress us

Be friendly / use Textile