Created
December 29, 2010 04:59
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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