diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-27 17:55:26 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-27 17:55:26 +0900 |
commit | 9a029046977916f35d98001f00692e35d570d1ee (patch) | |
tree | 1ce868b2b91061195d596eaf75e17b51b469fbe9 /src | |
parent | 2c4e8c299c375c23f2b83ab3e6ff95131833599e (diff) |
use keypress
Diffstat (limited to 'src')
-rw-r--r-- | src/background/index.js | 11 | ||||
-rw-r--r-- | src/content/index.js | 19 |
2 files changed, 7 insertions, 23 deletions
diff --git a/src/background/index.js b/src/background/index.js index f1a7217..7618384 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -6,13 +6,10 @@ import KeyQueue from './key-queue'; const queue = new KeyQueue(); -const keyDownHandle = (request, sender, sendResponse) => { +const keyPressHandle = (request, sender, sendResponse) => { let action = queue.push({ code: request.code, - shift: request.shift, - ctrl: request.ctrl, - alt: request.alt, - meta: request.meta + ctrl: request.ctrl }); if (!action) { return; @@ -76,8 +73,8 @@ const cmdEnterHandle = (request, sender) => { browser.runtime.onMessage.addListener((request, sender, sendResponse) => { switch (request.type) { - case 'event.keydown': - keyDownHandle(request, sender, sendResponse); + case 'event.keypress': + keyPressHandle(request, sender, sendResponse); break; case 'event.cmd.enter': cmdEnterHandle(request, sender, sendResponse); diff --git a/src/content/index.js b/src/content/index.js index feb169f..6bf5d57 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -66,27 +66,14 @@ const invokeEvent = (action) => { } } -const isModifier = (code) => { - return code === KeyboardEvent.DOM_VK_SHIFT || - code === KeyboardEvent.DOM_VK_ALT || - code === KeyboardEvent.DOM_VK_CONTROL || - code === KeyboardEvent.DOM_VK_META; -} - -window.addEventListener("keydown", (e) => { +window.addEventListener("keypress", (e) => { if (e.target instanceof HTMLInputElement) { return; } - if (isModifier(e.keyCode)) { - return; - } let request = { - type: 'event.keydown', - code: e.keyCode, - shift: e.shiftKey, - alt: e.altKey, - meta: e.metaKey, + type: 'event.keypress', + code: e.which, ctrl: e.ctrlKey, } |