0

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?

Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278

1 Answers1

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