How to make CAPSLOCK TurnOn Automatically on page, when capslock is OFF, using JavaScript.
-
1How would you like it if this happens without you noticing? It's impossible, trust me. People who write browsers are no idiots (except perhaps for those who wrote IE, assuming IE is a browser). – Jan 26 '11 at 16:26
-
4That doesn't sound like a good idea/feature. – Jan 26 '11 at 16:27
8 Answers
You cannot manipulate the caps lock state in javascript.
In general, you cannot simulate any keypress, except on the page itself. Javascript is in general sandboxed so that no website can affect anything else. Allowing it to send keypresses would allow all sorts of havoc to occur.

- 49,493
- 11
- 100
- 118
Why not use CSS to force the text to upper-case-case (and then make sure it's upper-case when you come to process the form)? this question explains how to do it with CSS and JavaScript too.
Have you considered capturing the keyUp event and converting all alphabetic characters to caps if they are not? Assign something like the following function to the onkeyup
event of whatever fields you care about (code is from liewcf.com):
function uppercase() {
key = window.event.keyCode;
if ((key > 0x60) && (key < 0x7B)) {
window.event.keyCode = key-0x20;
}
}

- 24,791
- 9
- 70
- 92
You cannot modify client system settings using Javascript, without using external libraries.

- 2,300
- 16
- 20
I don't think you can but why not use the CSS property "text-transform" set to "capitalize" instead?

- 2,608
- 1
- 19
- 32
You can't, and shouldn't.
What you can do is have your input elements convert text typed in mixed case to upper case, as the text is typed or afterward.

- 1,031,962
- 187
- 1,923
- 1,875
I'm afraid you can't simulate key pressing in JavaScript it would be security hole. But you still can detect if caps lock is enabled. Found an example.

- 2,526
- 3
- 25
- 32
Just set CSS style text-transform: capitalize
and when processing form data put the text through some capitalization function.

- 159,371
- 13
- 185
- 298