W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2010

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

From: Hallvord R. M. Steen <hallvord@opera.com>
Date: Wed, 22 Sep 2010 15:44:03 +0900
To: "Boris Zbarsky" <bzbarsky@mit.edu>, "Doug Schepers" <schepers@w3.org>, "Hallvord R. M. Steen" <hallvord@opera.com>
Cc: "Simon Pieters" <simonp@opera.com>, www-dom@w3.org
Message-ID: <op.vje8zpsza3v5gv@hr-opera>
On Fri, 17 Sep 2010 12:14:45 +0900, Hallvord R. M. Steen  
<hallvord@opera.com> 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!

[1]  
http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#events-KeyboardEvent-keyCode

-- 
Hallvord R. M. Steen, Core Tester, Opera Software
http://www.opera.com http://my.opera.com/hallvors/


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

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:05 GMT