Skip to content

Instantly share code, notes, and snippets.

@e-jigsaw
Last active December 13, 2015 17:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-jigsaw/4945744 to your computer and use it in GitHub Desktop.
Save e-jigsaw/4945744 to your computer and use it in GitHub Desktop.
Chrome extensionsでkeydown eventを発火させたいのだけれど、どうにも発火してくれない
some "event", ->
evt = document.createEvent "KeyboardEvent"
evt.initKeyboardEvent "keydown", true, true, null, "J".charCodeAt(0), false, false, false, 0
document.dispatchEvent evt # 何も起きない
@e-jigsaw
Copy link
Author

ちゃんと確認してみたら発火してる。でも、 evt.keyCode とかが0に設定されてて効いてくれないっぽい。

http://stackoverflow.com/questions/8942678/keyboardevent-in-chrome-keycode-is-0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment