CTalkobt.Net




Programming Newsgroup Tips & Tricks CubeCart Stuff
Subject: Re: keycodes - same for uppercase and lowercase?
From: RobG
Date: Mon, 26 Sep 2005 03:19:29 GMT
Newsgroups: comp.lang.javascript
X-Mozilla-Status: 0011
X-Mozilla-Status2: 00000000
Path: bigbe1.bellsouth.net!bigfeed.bellsouth.net!news.bellsouth.net!newsfeed2.telusplanet.net!newsfeed.telus.net!cyclone.bc.net!newsfeed.media.kyoto-u.ac.jp!news1.optus.net.au!optus!news.optus.net.au!53ab2750!not-for-mail
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: comp.lang.javascript
References: <1127700426.720583.282480@z14g2000cwz.googlegroups.com>
In-Reply-To:
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 64
Message-ID: <5NJZe.627$uQ6.31937@news.optus.net.au>
NNTP-Posting-Host: 203.15.126.10
X-Trace: news.optus.net.au 1127704769 203.15.126.10 (Mon, 26 Sep 2005 13:19:29 EST)
NNTP-Posting-Date: Mon, 26 Sep 2005 13:19:29 EST
Xref: bigfeed.bellsouth.net comp.lang.javascript:580519

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