"VK" <sc**********@yahoo.com> schreef in bericht
news:11*********************@p10g2000cwp.googlegro ups.com...
Pugi! wrote:
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.
No it's not ;-) Do not mix keyboard *scancodes* with *keycode*.
Scancode is the system value assigned to each key on your keyboard.
This value is indead layout-independent. Keycode is Unicode value going
to receiver: it depends on current layout, shift state etc.
In your particular case though it may help to monitor 'okeypress'
instead of 'onkeydown' as you're doing right now.
---
Well, actually I used onkeyup. But onkeypress only made it work for IE. So I
looked elswewhere in the code and keyCode is for IE, while Mozilla (and
rest) prefers charCode. But according to the author keyCode works fine in
Mozilla, guess he didn't debug his code hard enough.
function aKeyWasPressed(e) {
if (window.event) {
var key = window.event.keyCode;
} else {
var key = e.charCode; // changed keyCode to charCode for
Mozilla
}
alert('You pressed the key: ' + String.fromCharCode(key));
}
thanx,
Pugi!