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 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);

@ -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,
}