RobG wrote:[color=blue]
> Robert Mark Bram wrote:
>[color=green]
>> 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;
>> }[/color]
>
>
> 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.
>[/color]
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);
}
[color=blue]
>
> [...]
>[color=green]
>>
>> Why is this?[/color][/color]
I'll guess that it's because ASCII copied the ancient Bell 7-bit
teleprinter codes and modern keyboards continue the same scheme.
--
Rob