<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>19827</bug_id>
          
          <creation_ts>2012-11-02 08:40:41 +0000</creation_ts>
          <short_desc>map event.key to character values of a normal QUERTY  (en-US) layout</short_desc>
          <delta_ts>2013-08-25 18:04:10 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>HISTORICAL - DOM3 Events</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>blocker</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Hallvord R. M. Steen">hsteen</reporter>
          <assigned_to name="Travis Leithead [MSFT]">travil</assigned_to>
          <cc>bugs</cc>
    
    <cc>garykac</cc>
    
    <cc>mike</cc>
    
    <cc>mounir</cc>
    
    <cc>termi1uc1</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>77741</commentid>
    <comment_count>0</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-02 08:40:41 +0000</bug_when>
    <thetext>http://lists.w3.org/Archives/Public/public-webapps/2012OctDec/0319.html

I&apos;ve received feedback from JS authors trying to code for the new DOM3 Events implementation. According to this feedback, although the new spec attempts to be more i18n-friendly it is actually a step backwards compared to the event.keyCode model:

If, for example, you would like to do something when the user presses [Ctrl]-[1], under the old keyCode model you could write this in a keydown handler:

if(event.ctrlKey &amp;&amp; event.keyCode == 49)

while if you want to use the new implementation you will have to do something like

if(event.ctrlKey &amp;&amp; ( event.key == 1 || event.key == &apos;&amp;&apos; || event.key == &apos;1&apos; ))

and possibly even more variations, depending on what locales you want to support. (That&apos;s three checks for English ASCII, French AZERTY and Japanese hiragana &quot;wide character form&quot; layouts respectively - I don&apos;t know of other locales that assign other character values to this key but they might exist). 

Obviously, this makes it orders of magniture harder to write cross-locale applications and places a large burden of complexity on JS authors.

In the current spec, event.key and event.char are actually aliases of each other for most keys on the keyboard: if the key you press doesn&apos;t have a &quot;key name&quot; string, event.key and event.char are spec&apos;ed as being the same value.

This &quot;aliasing&quot; doesn&apos;t really add up to a clear concept. If two properties have the same value almost always, why do we add *two* new properties in the first place?

This is also the underlying cause for other reported problems with the new model, like the inability to match [Shift]-[A] keydown/up events because event.key might be a in keydown but A in keyup or vice versa.

I would like the &quot;story&quot; of event.char and event.key to be that event.char describes the generated character (if any) in its shifted/unshifted/modified/localized glory while event.key describes the key (perhaps on a best-effort basis, but in a way that is at least as stable and usable as event.keyCode).

Hence, what I think would be most usable in the real world would be making event.key a mapping back to un-shifted character values of a normal QUERTY (en-US) layout. Authors are asking for stable reference values for identifying keys, and that&apos;s the most stable and widely known reference keyboard layout.

Doing this will resolve https://www.w3.org/Bugs/Public/show_bug.cgi?id=18341 too. 

https://www.w3.org/Bugs/Public/show_bug.cgi?id=18867 is orthogonal. Doing what both this bug and 18867 suggests would imply some information loss (you will no longer be able to see the localized / modified character in a &quot;shortcut&quot;-type keypress like [Ctrl]-[A]), so that bug may have to be reconsidered if we go with this one.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77742</commentid>
    <comment_count>1</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-02 08:44:06 +0000</bug_when>
    <thetext>One example of the &quot;aliasing&quot; is where the spec describes event.key as follows: &quot;If the value is has a printed representation, it must match the value of the KeyboardEvent.char attribute&quot;

http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#events-KeyboardEvent-key</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77744</commentid>
    <comment_count>2</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2012-11-02 09:09:10 +0000</bug_when>
    <thetext>Don&apos;t understand where you get the event.key == 1 part.

Also, if user is using different locale, should it be expected that ctrl+1 in that locale maps to the
thing web pages tries to handle.
(Perhaps I&apos;m missing something here.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77749</commentid>
    <comment_count>3</comment_count>
    <who name="Egor Khalimonenko">termi1uc1</who>
    <bug_when>2012-11-02 10:55:06 +0000</bug_when>
    <thetext>I created a test page to demonstrate this proposal.

http://h123.ru/-/tests/KeyboardEvent/index.html

It using my polyfill that in [working in progress] status, so it has a few bugs and not working in old IE (lt 9).

Note: If you have problems in Opera, turn off &quot;output&quot; option in &quot;Options&quot; section.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92552</commentid>
    <comment_count>4</comment_count>
    <who name="Gary Kacmarcik">garykac</who>
    <bug_when>2013-08-25 18:04:10 +0000</bug_when>
    <thetext>The DOM3 spec has changed considerably since this bug was filed and we&apos;re addressing the problems stated here in the following ways:

The &apos;char&apos; attribute has been removed since it was only used by the deprecated keypress event.

We have introduced a &apos;code&apos; attribute in the UI Events spec to identify individual keys. This attribute will allow JS authors to check for a specific key press without needing to worry about the current keyboard locale.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>