parent
b694afb7ce
commit
d4e4b75414
4 changed files with 112 additions and 59 deletions
@ -1,29 +1,31 @@ |
|||||||
import { EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP } from '../shared/messages'; |
import { EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP } from '../shared/messages'; |
||||||
import * as ipc from './ipc'; |
import * as ipc from './ipc'; |
||||||
|
|
||||||
const press = (tabId, key) => { |
const NEUTRAL_MODIFIERS = { shiftKey: false, altKey: false, ctrlKey: false }; |
||||||
return ipc.send({ |
|
||||||
|
const press = (tabId, key, modifiers = NEUTRAL_MODIFIERS) => { |
||||||
|
return ipc.send(Object.assign({}, modifiers, { |
||||||
type: EVENT_KEYPRESS, |
type: EVENT_KEYPRESS, |
||||||
tabId, |
tabId, |
||||||
key, |
key, |
||||||
}); |
})); |
||||||
}; |
}; |
||||||
|
|
||||||
const down = (tabId, key) => { |
const down = (tabId, key, modifiers = NEUTRAL_MODIFIERS) => { |
||||||
return ipc.send({ |
return ipc.send(Object.assign({}, modifiers, { |
||||||
type: EVENT_KEYDOWN, |
type: EVENT_KEYDOWN, |
||||||
tabId, |
tabId, |
||||||
key, |
key, |
||||||
}); |
})); |
||||||
}; |
}; |
||||||
|
|
||||||
|
|
||||||
const up = (tabId, key) => { |
const up = (tabId, key, modifiers = NEUTRAL_MODIFIERS) => { |
||||||
return ipc.send({ |
return ipc.send(Object.assign({}, modifiers, { |
||||||
type: EVENT_KEYUP, |
type: EVENT_KEYUP, |
||||||
tabId, |
tabId, |
||||||
key, |
key, |
||||||
}); |
})); |
||||||
}; |
}; |
||||||
|
|
||||||
export { press, down, up }; |
export { press, down, up }; |
||||||
|
@ -0,0 +1,31 @@ |
|||||||
|
const keypress = (opts) => { |
||||||
|
let event = new KeyboardEvent('keypress', { |
||||||
|
key: opts.key, |
||||||
|
altKey: opts.altKey, |
||||||
|
shiftKey: opts.shiftKey, |
||||||
|
ctrlKey: opts.ctrlKey |
||||||
|
}); |
||||||
|
document.body.dispatchEvent(event); |
||||||
|
}; |
||||||
|
|
||||||
|
const keydown = (opts) => { |
||||||
|
let event = new KeyboardEvent('keydown', { |
||||||
|
key: opts.key, |
||||||
|
altKey: opts.altKey, |
||||||
|
shiftKey: opts.shiftKey, |
||||||
|
ctrlKey: opts.ctrlKey |
||||||
|
}); |
||||||
|
document.body.dispatchEvent(event); |
||||||
|
}; |
||||||
|
|
||||||
|
const keyup = (opts) => { |
||||||
|
let event = new KeyboardEvent('keyup', { |
||||||
|
key: opts.key, |
||||||
|
altKey: opts.altKey, |
||||||
|
shiftKey: opts.shiftKey, |
||||||
|
ctrlKey: opts.ctrlKey |
||||||
|
}); |
||||||
|
document.body.dispatchEvent(event); |
||||||
|
}; |
||||||
|
|
||||||
|
export { keypress, keydown, keyup }; |
Reference in new issue