Skip to content

Instantly share code, notes, and snippets.

@craigmccoy
Created December 29, 2010 04:59
Show Gist options
  • Save craigmccoy/758195 to your computer and use it in GitHub Desktop.
Save craigmccoy/758195 to your computer and use it in GitHub Desktop.
Function to detect whether or not CAPS LOCK key is active. Source: http://dougalmatthews.com/articles/2008/jul/2/javascript-detecting-caps-lock/
function isCapslock(e) {
e = (e) ? e : window.event;
var charCode = false;
if (e.which) {
charCode = e.which;
} else if (e.keyCode) {
charCode = e.keyCode;
}
var shifton = false;
if (e.shiftKey) {
shifton = e.shiftKey;
} else if (e.modifiers) {
shifton = !!(e.modifiers & 4);
}
if (charCode >= 97 && charCode <= 122 && shifton) {
return true;
}
if (charCode >= 65 && charCode <= 90 && !shifton) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment