Determine if caps lock is on with MooTools
This is a quick idea I came up with. We extend the Event native like this:
Event.implement({ hasCapsLock: function(){ return ((this.code > 64 && this.code < 91 && !this.shift) || (this.code > 96 && this.code < 123 && this.shift)); } });
And then access the method from a keypress event:
$('test').addEvent('keypress', function(event){ if (event.hasCapsLock()){ // do something } });
The only drawback is that it relies on sniffing alphabet characters and whether the shift key was pressed. This means that if the user presses the caps lock key, you won’t know it until another character is inserted.
