Re: [DOM3Events] keyCode and charCode [ISSUE-133]

On Fri, 17 Sep 2010 12:14:45 +0900, Hallvord R. M. Steen  
<> wrote:

>>>> Please specify keyCode and charCode, even if marked as 'obsolete'.

>> very difficult (if possible at all) to specify keyCode and charCode in  
>> a way that would be consistent across browsers, or even the same  
>> browser on different platforms.

Looked at this again..

AFAIK, charCode is trivial to specify. In a keypress event that will  
generate character input, set charCode to the Unicode reference number  
(code point) of that character. (Basically, event.charCode =  
event.char.valueAt(0)). In keydown/up, set charCode to 0.

This is neither complicated nor bad for i18n - as far as I can tell - and  
should go into the spec without further ado.

That leaves us with event.keyCode - which *is* already specified in the  
KeyEvent interface! [1] But the spec doesn't specify how to set it to a  
suitable value. Now, this is also trivial to define if we say something  
like "Set keyCode to the virtual key code value returned by the operating  
system" and leave it at that.

However, I think we might go a bit further than that - to benefit  
implementations running on peculiar platforms that don't report typical  
virtual key codes. It's somewhat challenging to defer to the virtual  
keycode of the operating system where it's correct and harmless  
compat-wise to do so, and yet suggest some rules for converting the key  
code to something that's going to be fairly web compatible..but I'm  
attaching a suggested spec and propose this is integrated into the spec.

Criticism from developers welcome!


Hallvord R. M. Steen, Core Tester, Opera Software

Received on Wednesday, 22 September 2010 06:44:32 UTC