use keypress

jh-changes
Shin'ya Ueoka 7 years ago
parent 2c4e8c299c
commit 9a02904697
  1. 11
      src/background/index.js
  2. 19
      src/content/index.js

@ -6,13 +6,10 @@ import KeyQueue from './key-queue';
const queue = new KeyQueue(); const queue = new KeyQueue();
const keyDownHandle = (request, sender, sendResponse) => { const keyPressHandle = (request, sender, sendResponse) => {
let action = queue.push({ let action = queue.push({
code: request.code, code: request.code,
shift: request.shift, ctrl: request.ctrl
ctrl: request.ctrl,
alt: request.alt,
meta: request.meta
}); });
if (!action) { if (!action) {
return; return;
@ -76,8 +73,8 @@ const cmdEnterHandle = (request, sender) => {
browser.runtime.onMessage.addListener((request, sender, sendResponse) => { browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
switch (request.type) { switch (request.type) {
case 'event.keydown': case 'event.keypress':
keyDownHandle(request, sender, sendResponse); keyPressHandle(request, sender, sendResponse);
break; break;
case 'event.cmd.enter': case 'event.cmd.enter':
cmdEnterHandle(request, sender, sendResponse); cmdEnterHandle(request, sender, sendResponse);

@ -66,27 +66,14 @@ const invokeEvent = (action) => {
} }
} }
const isModifier = (code) => { window.addEventListener("keypress", (e) => {
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) => {
if (e.target instanceof HTMLInputElement) { if (e.target instanceof HTMLInputElement) {
return; return;
} }
if (isModifier(e.keyCode)) {
return;
}
let request = { let request = {
type: 'event.keydown', type: 'event.keypress',
code: e.keyCode, code: e.which,
shift: e.shiftKey,
alt: e.altKey,
meta: e.metaKey,
ctrl: e.ctrlKey, ctrl: e.ctrlKey,
} }