KeyboardEventInit doesn't support supplementary codes |
||
Issue description
Chrome Version: 57.0.2970.0 dev
What steps will reproduce the problem?
(1) Create a KeyboardEvent with a specific |keyCode| value, e.g. var foo = new KeyboardEvent("keydown", { "keyCode": 45 })
What is the expected result?
|foo| should be a KeyboardEvent with |keyCode| set to 45.
What happens instead?
KeyboardEvent has |keyCode| set to zero.
Although |keyCode| is a deprecated DOM KeyboardEvent field, it should be possible to set it in synthetic events, to allow injection of input to legacy content.
Note that although we could synthesize |keyCode| from |key|/|code|, doing so is not straightforward unless we assume some default layout, which is undesirable.
,
Jan 9 2017
In this case I was attempting to inject keystrokes into some legacy content, the HTML5/JS game braains.io These were the docs I was trying to follow: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent This is the hack people use to work around it: var eventObj = document.createEvent("Events"); eventObj.initEvent("keydown", true, true); eventObj.keyCode = keyCode; eventObj.which = keyCode; document.dispatchEvent(eventObj); SO has some discussion http://stackoverflow.com/questions/8942678/keyboardevent-in-chrome-keycode-is-0/12522752
,
Dec 11 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/a3c788a1d8dfb2c243aa6f1c93300ecd5a0bc5d2 commit a3c788a1d8dfb2c243aa6f1c93300ecd5a0bc5d2 Author: Dave Tapuska <dtapuska@chromium.org> Date: Mon Dec 11 21:25:37 2017 Support setting charCode/keyCode from KeyboardEventInit We didn't support setting keyCode/charCode from the KeyboardEventInit which other vendors did. Approved intent to ship: https://groups.google.com/a/chromium.org/d/msg/blink-dev/wEm8WWPpxU4/S4sLZgQNBgAJ BUG= 679439 Change-Id: I2f817fa71ec09f80650ec458edfffe6ab328eb02 Reviewed-on: https://chromium-review.googlesource.com/793989 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Mustaq Ahmed <mustaq@chromium.org> Cr-Commit-Position: refs/heads/master@{#523212} [delete] https://crrev.com/0aca5783cda357e74a2ec6728fd82bf0c510579e/third_party/WebKit/LayoutTests/external/wpt/dom/events/Event-subclasses-constructors-expected.txt [modify] https://crrev.com/a3c788a1d8dfb2c243aa6f1c93300ecd5a0bc5d2/third_party/WebKit/Source/core/events/KeyboardEvent.cpp [modify] https://crrev.com/a3c788a1d8dfb2c243aa6f1c93300ecd5a0bc5d2/third_party/WebKit/Source/core/events/KeyboardEvent.h [modify] https://crrev.com/a3c788a1d8dfb2c243aa6f1c93300ecd5a0bc5d2/third_party/WebKit/Source/core/events/KeyboardEventInit.idl
,
Dec 11 2017
|
||
►
Sign in to add a comment |
||
Comment 1 by dtapu...@chromium.org
, Jan 9 2017Owner: dtapu...@chromium.org
Status: Assigned (was: Untriaged)
Summary: KeyboardEventInit doesn't support supplementary codes (was: keyCode parameter to KeyboardEvent constructore is ignored, and results in events with keyCode=0)