I'm implementing a keyboard handler that writes a text node, and i'm having difficulties understanding how to handle the case of special characters like accentuated ones such as å or á or even è, usually what i would use depending on the browser would be something like this :
function stringFromKeyPress(event) {
if (event.which === null || event.which === undefined) {
return String.fromCharCode(event.keyCode); // IE
}
if (event.which !== 0 && event.charCode !== 0) {
return String.fromCharCode(event.which); // the rest
}
return null; // special key
}
and then from the returned value i would insert the character into the text node, it works perfectly fine for normal characters cause the keyCode or charCode that some browsers return translate perfectly for the Unicode characters that String.fromCharCode(code) accepts. But the problem i have is with the dead-keys or when i have to make a composite combo, for example when i press the grave accent (´) and then press the key (a) i'm expecting the result to be á however the browser fires up one keyup and down event for the (´) with keyCode 221 and then when i press (a) it fires up the keydown->keypress->keyup normal sequence with the (a) code 65 for keydown/up and 97 for keypress.
My question is how do i handle the dead-key composition combo? How do i tell the browser that when i press the grave accent to wait for a possibly valid key that's coming and if it does to input it?
I hope I am clear in my explanation, if you need additional details just ask.