Determining caps lock state

R

Robert

Hi!

I was wondering if the was any way to determine the state of the caps
lock key, on or off.
Of course I can capture the key events and see whether the caps lock is
pressed, but that does not help.

I have seen some example that looks at the characters entered in an
input field to determine if the caps lock is on, but I was wondering if
something is possible that is a bit more immediate to report the caps
lock state.

Robert.
 
R

rf

Robert said:
Hi!

I was wondering if the was any way to determine the state of the caps
lock key, on or off.
Of course I can capture the key events and see whether the caps lock is
pressed, but that does not help.

I have seen some example that looks at the characters entered in an
input field to determine if the caps lock is on, but I was wondering if
something is possible that is a bit more immediate to report the caps
lock state.

Why?
 
R

Robert

rf said:
Robert wrote:



Why?

It is to alert that the caps lock is enabled on a form where a user can
change his password. I want to make a block visible when the caps lock
is enabled and hide it again when it is off.
I prefer to do it as similar as we do in a swing client.
 
R

rf

Robert said:
It is to alert that the caps lock is enabled

I have a little light on my keyboard that indicates my caps lock status.
on a form where a user can
change his password.

Password fields should be, well, type="password" fields.
I want to make a block visible when the caps lock
is enabled and hide it again when it is off.

You are trying to change the behaviour of my browser. Don't. How do you
know I even *have* a caps lock button?
I prefer to do it as similar as we do in a swing client.

What is a "swing client"?
 
E

Evertjan.

Robert wrote on 27 okt 2005 in comp.lang.javascript:
It is to alert that the caps lock is enabled on a form where a user can
change his password. I want to make a block visible when the caps lock
is enabled and hide it again when it is off.
I prefer to do it as similar as we do in a swing client.

Better make the serverside password parsing caseinsensitive,

jscript-ASP:

password = request.form('password').toLowerCase();

or even better [securitywize] "case reversed" serverside,
and allow testing for both password and password2:

jscript-ASP:

password = request.form('password');
password2 = '';
for (i=0;i<password.length;i++){
l = password.charAt(i);
password2 +=
(l==l.toLowerCase())
?l.toUpperCase():l.toLowerCase();
};

[can this be done by regex, I wonder?]
 
J

Julian Turner

Robert said:
Hi!

I was wondering if the was any way to determine the state of the caps
lock key, on or off.
Of course I can capture the key events and see whether the caps lock is
pressed, but that does not help.

I have seen some example that looks at the characters entered in an
input field to determine if the caps lock is on, but I was wondering if
something is possible that is a bit more immediate to report the caps
lock state.

Robert.

I don't think you can do it within Javascript alone. Even Visual Basic
has to use an external user32.dll to get the caps lock state.

Here is a site with some kind of suggestion:-

http://www.howtocreate.co.uk/jslibs/htmlhigh/capsDetect.html

Can't vouch for it though.

Julian
 
R

Robert

rf said:
I have a little light on my keyboard that indicates my caps lock status.

lol
Well it is neither for me or you. You should know how many regular users
have had problems with caps-lock and passwords.
Password fields should be, well, type="password" fields.

Uhmmm... yes of course. If they were type="text" then they could see
their uppercase characters and I would not ask for a caps-lock indication.
You are trying to change the behaviour of my browser. Don't.

I am not changing the behaviour of your browser.
Does the caps-lock indication in a 'normal' windows application change
your operating system?
How do you
know I even *have* a caps lock button?

Well if you don't have it then you will never see the indicator.
What is a "swing client"?

Sorry. I meant a Java application that uses Swing components.
 
R

Robert

Evertjan. said:
Robert wrote on 27 okt 2005 in comp.lang.javascript:


Better make the serverside password parsing caseinsensitive,

I would do that if I were responsible for the serverside.
Just busy making a webclient that resembles the Java swing client as
best what is possible.
jscript-ASP:

I use Apache Tapestry :)
 
R

Robert

Julian said:
Robert wrote:



I don't think you can do it within Javascript alone. Even Visual Basic
has to use an external user32.dll to get the caps lock state.

Here is a site with some kind of suggestion:-

http://www.howtocreate.co.uk/jslibs/htmlhigh/capsDetect.html

I found that already. The 'problem' with this is that the indicator
would only change when actually inside the input field and pressing a
character. Nothing would change by just pressing the caps-lock.

Anyway I have an idea now how it might be possible. If I succeed I will
post it on Monday.
 
E

Evertjan.

Robert wrote on 28 okt 2005 in comp.lang.javascript:
I would do that if I were responsible for the serverside.

<input type='password'
onblur='this.value=this.value.toLowerCase();'>

will do clientside, but you have to convince all users that haven't
all lowecase pwds to change them.
 
V

VK

Determining caps lock state

I may be missing some extra issue here, but where is the problem?
CapsLock Unicode value is 20
So just monitor it via keyDown or keyUp (not keyPress!)

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function init() {
document.onkeydown = test;
}

function test(e){
if (e) {
alert(e.which);
}
else {
alert(event.keyCode);
}
}
window.onload = init;
</script>
</head>

<body bgcolor="#FFFFFF">

</body>
</html>
 
R

Randy Webb

VK said the following on 10/28/2005 8:48 AM:
I may be missing some extra issue here, but where is the problem?
CapsLock Unicode value is 20
So just monitor it via keyDown or keyUp (not keyPress!)

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function init() {
document.onkeydown = test;
}

function test(e){
if (e) {
alert(e.which);
}
else {
alert(event.keyCode);
}
}
window.onload = init;
</script>
</head>

<body bgcolor="#FFFFFF">

</body>
</html>

Because that does not tell you the state it is in. Only if the key was
pressed.
 
R

Robert

Evertjan. said:
Robert wrote on 28 okt 2005 in comp.lang.javascript:



<input type='password'
onblur='this.value=this.value.toLowerCase();'>

will do clientside, but you have to convince all users that haven't
all lowecase pwds to change them.

Thanks, but it really is not an option.
 
R

Robert

Evertjan. said:
Robert wrote on 28 okt 2005 in comp.lang.javascript:




The latter is off topic.

I know... just for your information.
Anyway, neither Tapestry or javascript would have been the correct place
to implement lowercase password. Because that would not help those
changing passwords with their Java Swing application.
But all of this is getting off-topic.
 
B

BootNic

Robert said:
Hi!

I was wondering if the was any way to determine the state of the
caps lock key, on or off.
Of course I can capture the key events and see whether the caps
lock is pressed, but that does not help.

I have seen some example that looks at the characters entered in an
input field to determine if the caps lock is on, but I was
wondering if something is possible that is a bit more immediate to
report the caps lock state.

Robert.

http://www.howtocreate.co.uk/jslibs/otherdemo.html#cld
 
V

VK

There must be somewhere a pre-historic keysta32.ocx control for Windows
95 (CLASSID="clsid:B9D22270-0C24-101B-AEBD-04021C009402"). It gave you
Num Lock, Caps Lock and Scroll Lock states. You may try to find it and
see if it still works on current Windows dll's.

JavaScript / JScript by themselve have nothing to propose on this
matter within the chosen approach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top