473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

keycodes - same for uppercase and lowercase?

Hi All,

This page:
http://www.lookuptables.com/
shows that the decimal ASCII code for 'A' is 65 and 'a' is 97.

Yet I find that the following code in Firefox and IE show 65 for a and
A.

<html>
<head>
<script type="text/javascript">
function keyPressed(event) {
if (event == null) {
event = window.event;
}
var keycode;
if (window.event) {
keycode = window.event.keyCode;
} else if (event) {
keycode = event.which;
}
alert(keycode);
}
</script>
</head>
<body>
<form>
<input type="text" onkeyup="keyPressed(event);"/>
</form>
</body>
</html>

Why is this?

Rob
:)

Sep 26 '05 #1
5 14855
Robert Mark Bram wrote:
Hi All,

This page:
http://www.lookuptables.com/
shows that the decimal ASCII code for 'A' is 65 and 'a' is 97.

Yet I find that the following code in Firefox and IE show 65 for a and
A.

<html>
<head>
<script type="text/javascript">
function keyPressed(event) {
if (event == null) {
event = window.event;
}
This test seems redundant. If 'event' is null, then you have the IE
event model and so use window.event. The local variable 'event' is not
used so there seems little point in using it.

But that could be just plain picky :-)

[...]

Why is this?


See of this recent post helps any ("Associating keys to a function"):

<URL:http://groups.google.co.uk/group/comp.lang.javascript/browse_frm/thread/833757766c208858/627d4ee7f722a3a4?tvc=1&q=modifier+keys+onkeypress+ keycode+which&hl=en#627d4ee7f722a3a4>
--
Rob
Sep 26 '05 #2
RobG wrote:
Robert Mark Bram wrote:
Hi All,

This page:
http://www.lookuptables.com/
shows that the decimal ASCII code for 'A' is 65 and 'a' is 97.

Yet I find that the following code in Firefox and IE show 65 for a and
A.

<html>
<head>
<script type="text/javascript">
function keyPressed(event) {
if (event == null) {
event = window.event;
}

This test seems redundant. If 'event' is null, then you have the IE
event model and so use window.event. The local variable 'event' is not
used so there seems little point in using it.


I'll correct that. Better to use feature detection for the feature you
are checking for, not some other feature that you think infers the
feature you'd like to use.

i.e. if you want to check for event.keyCode, then check for that, don't
check for window.event and presume that means support for event.keyCode
(although it will likely work nearly always...).

function keyPressed( e )
{
var e = e || window.event;
var keycode='Key pressed: ';
if (e.keyCode) {
keycode += e.keyCode;
} else if (e.which){
keycode += e.which;
} else {
return;
}
keycode += '\nAlt key pressed? ' + e.altKey;
keycode += '\nShift key pressed? ' + e.shiftKey;
keycode += '\nCtrl key pressed? ' + e.ctrlKey;

alert(keycode);
}

[...]

Why is this?


I'll guess that it's because ASCII copied the ancient Bell 7-bit
teleprinter codes and modern keyboards continue the same scheme.
--
Rob
Sep 26 '05 #3
Hi Rob,
Why is this?
I'll guess that it's because ASCII copied the ancient Bell 7-bit
teleprinter codes and modern keyboards continue the same scheme.


Not sure I understand this answer. Why can we type an 'a' or 'A' into a
text area and it knows whether we are typing an upper or lower case
letter, but JavaScript can't? Aren't they working from the same event
model i.e. an event object and keycode provided by the browser?

Rob
:)

Sep 26 '05 #4
rf

"Robert Mark Bram" <re********@optusnet.com.au> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi Rob,
Why is this?

I'll guess that it's because ASCII copied the ancient Bell 7-bit
teleprinter codes and modern keyboards continue the same scheme.


Not sure I understand this answer. Why can we type an 'a' or 'A' into a
text area and it knows whether we are typing an upper or lower case
letter, but JavaScript can't? Aren't they working from the same event
model i.e. an event object and keycode provided by the browser?


You are missing the point. You are hooking the keyup event. This is a low
level keyboard event, there has been no translation yet to upper/lower case.

There is only one A key. The difference between an a and an A is the state
of the shift key.

Look at event.shiftKey. If set then the shift key is pressed. You might also
need to look at
Sep 26 '05 #5
Robert Mark Bram wrote:
Hi Rob,

Why is this?


I'll guess that it's because ASCII copied the ancient Bell 7-bit
teleprinter codes and modern keyboards continue the same scheme.

Not sure I understand this answer. Why can we type an 'a' or 'A' into a
text area and it knows whether we are typing an upper or lower case
letter, but JavaScript can't? Aren't they working from the same event
model i.e. an event object and keycode provided by the browser?


RF was on the trail but seems to have posted prematurely...

The keycode for the A key is the code for the key, not the letter. If
the shift key is pressed at the same time, the computer says 'Oh, shift
and A are pressed simultaneously, let's pass that to the application'.
The application then decides what to do with it - usually make it a
capital 'A'.

If Ctrl+A are pressed, then most applications will select everything in
the window in focus, and so on.

Some keys are not passed to the JavaScript interface - F1 is nearly
always used for help and is used by the browser, it isn't passed through
to the script engine.

--
Rob
Sep 26 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Hallvard B Furuseth | last post by:
Has someone got a Python routine or module which converts Unicode strings to lowercase (or uppercase)? What I actually need to do is to compare a number of strings in a case-insensitive manner,...
8
by: Markus Dehmann | last post by:
My ios::uppercase (and others) seems not to work. #include <iostream> using namespace std; int main(){ int num = 45; cout.setf(ios::hex | ios::showbase | ios::uppercase); cout << "number " <<...
1
by: The_Kingpin | last post by:
Hi all, I need to make a function that convert a string into a certain format. Here what are the restriction: -The first letter of the first and last name must be uppercase. -If a first name...
6
by: BSHELTON | last post by:
How do I convert existing lowercase data to uppercase in Access 2000? I used the following which did not work? UPDATE HousingTowns SET tMunis=UPPER(tMunis); "HousingTowns" is the table name....
2
by: t8ntboy | last post by:
I have a table the contains field called PersonID. Each record in the personID field begins with the letter "p" in uppercase or lowercase. I want to run a query that finds all of the lowercase...
4
by: titan nyquist | last post by:
Why does ToTitleCase not work if the case is already in upper case? I have to make my string lowercase, first, before I pass to to ToTitleCase to have it work. Titan
4
by: jerger | last post by:
i have a great program now with the help of a member from this site, but i need a little customization to meet the needs of non-english speakers... who might accidendtly type punctuation which would...
7
by: tom harrison | last post by:
i'm so glad i found this forum! i have to have some coursework done by the end of the week and i really need it explaining to me. i'm not really that big on stuff like this but it's a part of my web...
9
by: humaid | last post by:
hi guys,i have this problem.first let me show you the so far code #!/user/bin/perl while ($a = <STDIN>) { if ($a =~ tr/A-Z/a-z/) { print "$a\n"; }
1
by: peacock97 | last post by:
I have an access mailing list. I received it in UPPERCASE and have been able to change the 1st letter to UPPERCASE and the rest to lowercase except that in Proper Names like McDonald, McInnis, they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.