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 * as ipc from './ipc'; |
||||
|
||||
const press = (tabId, key) => { |
||||
return ipc.send({ |
||||
const NEUTRAL_MODIFIERS = { shiftKey: false, altKey: false, ctrlKey: false }; |
||||
|
||||
const press = (tabId, key, modifiers = NEUTRAL_MODIFIERS) => { |
||||
return ipc.send(Object.assign({}, modifiers, { |
||||
type: EVENT_KEYPRESS, |
||||
tabId, |
||||
key, |
||||
}); |
||||
})); |
||||
}; |
||||
|
||||
const down = (tabId, key) => { |
||||
return ipc.send({ |
||||
const down = (tabId, key, modifiers = NEUTRAL_MODIFIERS) => { |
||||
return ipc.send(Object.assign({}, modifiers, { |
||||
type: EVENT_KEYDOWN, |
||||
tabId, |
||||
key, |
||||
}); |
||||
})); |
||||
}; |
||||
|
||||
|
||||
const up = (tabId, key) => { |
||||
return ipc.send({ |
||||
const up = (tabId, key, modifiers = NEUTRAL_MODIFIERS) => { |
||||
return ipc.send(Object.assign({}, modifiers, { |
||||
type: EVENT_KEYUP, |
||||
tabId, |
||||
key, |
||||
}); |
||||
})); |
||||
}; |
||||
|
||||
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