What's wrong with keyCode and String.fromCharCode
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

What's wrong with keyCode and String.fromCharCode

From: Pugi! <reply@group.be>
Date: Mon Feb 27 2006 - 17:33:53 CET

I got this (piece of) script from 'DHTML Utopia - Modern Webdesign - Using
Javascript & DOM'.

function aKeyWasPressed(e) {
        if (window.event) {
          var key = window.event.keyCode;
        } else {
          var key = e.keyCode;
        }
        alert('You pressed the key: ' + String.fromCharCode(key));
      }

It is example of adding an eventlistener to a textarea. The events works
alright, but when I press 'a' the alert gives me 'A', when I press '8' I get
'h', when I press '0' I get ''', when I press 'à' I get '0', ....
Has probably something to do with the fact that I don't live in the UK or
USA. But it shouldn't matter; a key is a key.

Pugi!
Received on Mon May 1 03:39:44 2006