By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,136 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,136 IT Pros & Developers. It's quick & easy.

Determining caps lock state

P: n/a
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.
Oct 27 '05 #1
Share this Question
Share on Google+
18 Replies


P: n/a
rf
Robert wrote:
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?

--
Cheers
Richard.
Oct 27 '05 #2

P: n/a
rf wrote:
Robert wrote:

Hi!

I was wondering if the was any way to determine the state of the caps
lock key, on or off.


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.
Oct 27 '05 #3

P: n/a
rf
Robert wrote:
rf wrote:
Robert wrote:
Hi!

I was wondering if the was any way to determine the state of the caps
lock key, on or off.
Why?


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"?

--
Cheers
Richard.
Oct 27 '05 #4

P: n/a
Robert wrote on 27 okt 2005 in comp.lang.javascript:
rf wrote:
Robert wrote:
I was wondering if the was any way to determine the state of the caps
lock key, on or off.


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.


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?]

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 27 '05 #5

P: n/a

Robert wrote:
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/...apsDetect.html

Can't vouch for it though.

Julian

Oct 27 '05 #6

P: n/a
In article <j0*****************************@40tude.net>,
rf <rf@invalid.com> wrote:
Robert wrote:
rf wrote:
Robert wrote:

Hi!

I was wondering if the was any way to determine the state of the caps
lock key, on or off.

Why?


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?


No he's not. He's trying to provide additional visual feedback. If
that's an example of changing the behavior of your browser, then so is
alert("password is case sensitive");

That said, it does strike me as a quixotic quest.
Oct 27 '05 #7

P: n/a
rf wrote:
Robert wrote:
I was wondering if the was any way to determine the state of the caps
lock key, on or off.

Why?
It is to alert that the caps lock is enabled

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.
on a form where a user can
change his password.

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.
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.


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.
I prefer to do it as similar as we do in a swing client.

What is a "swing client"?


Sorry. I meant a Java application that uses Swing components.
Oct 28 '05 #8

P: n/a
Evertjan. wrote:
Robert wrote on 27 okt 2005 in comp.lang.javascript:

rf wrote:
Robert wrote:

I was wondering if the was any way to determine the state of the caps
lock key, on or off.
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 :)
Oct 28 '05 #9

P: n/a
Julian Turner wrote:
Robert wrote:

Hi!

I was wondering if the was any way to determine the state of the caps
lock key, on or off.


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/...apsDetect.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.
Oct 28 '05 #10

P: n/a
Robert wrote on 28 okt 2005 in comp.lang.javascript:
jscript-ASP:


I use Apache Tapestry :)


The latter is off topic.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 28 '05 #11

P: n/a
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.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 28 '05 #12

P: n/a
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>

Oct 28 '05 #13

P: n/a
VK said the following on 10/28/2005 8:48 AM:
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>


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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 28 '05 #14

P: n/a
Evertjan. wrote:
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.


Thanks, but it really is not an option.
Oct 28 '05 #15

P: n/a
Evertjan. wrote:
Robert wrote on 28 okt 2005 in comp.lang.javascript:

jscript-ASP:


I use Apache Tapestry :)

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.
Oct 28 '05 #16

P: n/a
> "Robert" <ro****@noreply.x> wrote:
news:43***********************@news.xs4all.nl....

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

--
BootNic Friday, October 28, 2005 9:01 PM

I try to take one day at a time, but sometimes several days attack me at once.
*Jennifer Unlimited*

Oct 29 '05 #17

P: n/a
BootNic wrote:
"Robert" <ro****@noreply.x> wrote:
news:43***********************@news.xs4all.nl... .

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


Thanks, but like I said I know about this already.
I was looking for something better.
Oct 29 '05 #18

P: n/a
VK

Robert wrote:
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.


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.

Oct 30 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.