I would like to alert users that their caps-lock is pressed.
I am using HTML/HTML5 no Java (applets) nor Flash.
Is there a way to know that?
Asked
Active
Viewed 182 times
0

Itay Moav -Malimovka
- 52,579
- 61
- 190
- 278
-
http://stackoverflow.com/questions/11881359/check-for-capslock-on-in-onfocus-event – Rookie Programmer Aravind Feb 17 '14 at 02:54
-
http://stackoverflow.com/questions/11881359/check-for-capslock-on-in-onfocus-event – Rookie Programmer Aravind Feb 17 '14 at 02:55
1 Answers
1
I do not think that it is possible in HTML but you can use JavaScript`s onKeyPress event for that.
Example:
function capLock(e){
kc = e.keyCode?e.keyCode:e.which;
sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
document.getElementById('divMayus').style.visibility = 'visible';
else
document.getElementById('divMayus').style.visibility = 'hidden';
}
</script>
HTML:
<input type="password" name="txtPassword" onkeypress="capLock(event)" />
<div id="divMayus" style="visibility:hidden">Caps Lock is on.</div>

Osama Yawar
- 361
- 2
- 6
- 19