DOM-Keyboard-Event-Level-3-polyfill
DOM-Keyboard-Event-Level-3-polyfill copied to clipboard
Chrome problems
Hi, this doesn't seem to work in Chrome (version 27.0.1453.116, Windows 7).
When entering the demo code into the Javascript console:
document.addEventListener("keydown", function(e){ console.log(e.type, e.key, e.char, e.shiftKey) })
document.dispatchEvent(new KeyboardEvent("keydown", { key: "1", char: "!", shiftKey: true }))
... the console starts outputting
keydown undefined undefined false
... as if the key and char properties are not populated.
Is this perhaps related to https://bugs.webkit.org/show_bug.cgi?id=16735 ?
Hi. Do you try this demo is it working for you?
Can you do KeyboardEvent + "" in console and take a look is it not equal function KeyboardEvent() { [native code] }. If it does, it may indicate that the polyfill did not work. In this case, please run
(function( global ) {
try {
return (new global["KeyboardEvent"]( "keyup", {"key": "a"} ))["key"] == "a";
}
catch ( __e__ ) {
return false;
}
})( this )
in console and comment here the answer. If it true and KeyboardEvent + "" === function KeyboardEvent() { [native code] } the problem in my code. If it not the problem is somewhere else.
By the way, your case is working in my chrome currectly: http://clip.corp.mail.ru/clip/m198/1373747235-clip-50kb-xFUheGw5hJBc.png
Yes, that demo works, as in: The keydown and keyup columns reflect the key I'm pressing, but nothing happens in the keypress column (should it?). On that page, I can also paste
document.addEventListener("keydown", function(e){ console.log(e.type, e.key, e.char, e.shiftKey) })
document.dispatchEvent(new KeyboardEvent("keydown", { key: "1", char: "!", shiftKey: true }))
and it outputs
keydown j j false
keydown f f false
etc.
When entering KeyboardEvent + "" I get the constructor code:
"function _KeyboardEvent( type, dict ) {// KeyboardEvent constructor
etc.
So, everything seems to be working on that page. I'll have to check my code more thoroughly. Sorry about the noise.
keypress is deprecated so I decide not to polyfill it.
Sorry about the noise.
That's all right!