Syncing javascript keycode's across platforms

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Syncing javascript keycode's across platforms

Adam Treat-2
Hi,

Currently the keycodes returned by the various platforms under WebKit are
nowhere near close to uniform.  This seems like something that should be
standard across all platforms that WebKit provides.  It is unclear to me
exactly how the keycodes are generated by the different platforms...

In platform/qt/PlatformKeyboardEventQt.cpp the following snippet of code seems
to handle the return code for the up arrow key:

        case Qt::Key_Up:
            return VK_UP; // (26) UP ARROW key

The equivalent code for the mac would seem to be in
platform/mac/KeyEventMac.mm:

        // VK_UP (26) UP ARROW key
        case NSUpArrowFunctionKey: return 0x26;

The actual behavior under Safari seems to be to return '63232'

I am not at all aware how this happens.

The current mess for javascript keycodes is nicely summarized on this page.

http://www.unixpapa.com/js/key.html

If we can't fix this as a standard across browsers, surely this could be fixed
across platforms that WebKit provides, no?

Adam

PS Any clue as to where Safari turns that code into '63232' would be much
appreciated.
_______________________________________________
webkit-dev mailing list
[hidden email]
http://lists.webkit.org/mailman/listinfo/webkit-dev
Reply | Threaded
Open this post in threaded view
|

Re: Syncing javascript keycode's across platforms

Darin Adler
On Mar 28, 2007, at 3:43 PM, Adam Treat wrote:

> Currently the keycodes returned by the various platforms under  
> WebKit are nowhere near close to uniform.

Seems well worth fixing.

> This seems like something that should be standard across all  
> platforms that WebKit provides. It is unclear to me exactly how the  
> keycodes are generated by the different platforms.

It's easy to get confused because there are both key codes and  
character codes, and the keyCode and charCode functions behave  
differently for different event types.

Two functions to look at to understand the behavior are  
KeyboardEvent::keyCode and KeyboardEvent::charCode.

> The equivalent code for the mac would seem to be in platform/mac/
> KeyEventMac.mm:
>
>         // VK_UP (26) UP ARROW key
>         case NSUpArrowFunctionKey: return 0x26;
>
> The actual behavior under Safari seems to be to return '63232'

63232 is the value of NSUpArrowFunctionKey.

It would be good to survey behavior of other browsers, especially  
Internet Explorer, and change our behavior to match more closely.  
Please write a bug report once you have a clear idea what you think  
we should do.

     -- Darin

_______________________________________________
webkit-dev mailing list
[hidden email]
http://lists.webkit.org/mailman/listinfo/webkit-dev
Reply | Threaded
Open this post in threaded view
|

Re: Syncing javascript keycode's across platforms

David Hyatt
In reply to this post by Adam Treat-2
A couple of things to note here.  ToT is not the same as Safari 2, so  
keep that in mind.

event.keyCode is set to the Windows key code for keydown and keyup.  
This means you should have consistency now across WebKit impls for  
event.keyCode assuming everyone has implemented WindowsKeyCode  
properly.  For example on Mac if you alert for the down arrow key you  
get 4040 in a keydown/keyup.

For keypress, event.keyCode is equivalent to event.charCode.  The  
char code is obtained by getting the first character of the key  
event's "text" and returning that.  This text is initialized in  
platform/mac/KeyEventMac to be the raw characters of the event  
according to the platform.  In the case of down arrow for example,  
this means you'll get 62323.

Note that the Web API WG has taken over DOM Level 3 Events in order  
to better specify key events.  You can find that spec here:

http://www.w3.org/TR/DOM-Level-3-Events/events.html

keyCode/charCode are basically being scrapped in favor of  
keyIdentifier (implemented in ToT!), and - I believe - this system is  
designed to yield consistent results across platforms.

dave
([hidden email])

On Mar 28, 2007, at 3:43 PM, Adam Treat wrote:

> Hi,
>
> Currently the keycodes returned by the various platforms under  
> WebKit are
> nowhere near close to uniform.  This seems like something that  
> should be
> standard across all platforms that WebKit provides.  It is unclear  
> to me
> exactly how the keycodes are generated by the different platforms...
>
> In platform/qt/PlatformKeyboardEventQt.cpp the following snippet of  
> code seems
> to handle the return code for the up arrow key:
>
>         case Qt::Key_Up:
>             return VK_UP; // (26) UP ARROW key
>
> The equivalent code for the mac would seem to be in
> platform/mac/KeyEventMac.mm:
>
>         // VK_UP (26) UP ARROW key
>         case NSUpArrowFunctionKey: return 0x26;
>
> The actual behavior under Safari seems to be to return '63232'
>
> I am not at all aware how this happens.
>
> The current mess for javascript keycodes is nicely summarized on  
> this page.
>
> http://www.unixpapa.com/js/key.html
>
> If we can't fix this as a standard across browsers, surely this  
> could be fixed
> across platforms that WebKit provides, no?
>
> Adam
>
> PS Any clue as to where Safari turns that code into '63232' would  
> be much
> appreciated.
> _______________________________________________
> webkit-dev mailing list
> [hidden email]
> http://lists.webkit.org/mailman/listinfo/webkit-dev

_______________________________________________
webkit-dev mailing list
[hidden email]
http://lists.webkit.org/mailman/listinfo/webkit-dev