After my first batch of Security Tutorials were published on www.asp.net, a reader emailed me asking if it was possible to display some sort of warning if the user has Caps Lock on whilst entering their password into the Login control. While JavaScript cannot indicate if Caps Lock is on or not, you can ascertain whether it is once the user types an alphabetic key, as JavaScript can determine the key pressed and whether the Shift key was also pressed. In short, if the character is upper case and Shift is not depressed, or if the character is lowercase but Shift is depressed, then it follows that Caps Lock is on.
So it is possible to write a bit of JavaScript that fires when the user types a key into a TextBox and display some warning in response. This ASP.NET Forums post - Give Warning When Caps Lock On - discusses a JavaScript-based solution. The downside is that you have to paste in the necessary JavaScript into the page and add JavaScript to the TextBox control's onkeypressed client-side event. Wouldn't it be easier to be able to drag and drop a control onto the page, set a few properties and, presto, have a working Caps Lock warning?
My latest 4Guys article, Warning the User When Caps Lock is On, looks at building such a control. It is now part of my skmControls2 collection, which includes (currently) two other open-source server controls:
For more open-source, free tools, controls, and other funery, check out My Code Projects.
Enjoy!