Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const event = keys.reduce((event, attribute) => {
const isValidModifier = validModifiers.indexOf(attribute) > -1;
if (isValidModifier) {
attribute = attribute === 'cmd' ? getCmdKey() : attribute;
event[`${attribute}Key`] = true;
} else if (validMouseButtons.indexOf(attribute) > -1) {
event.button = getMouseCode(attribute);
} else {
const keyCode = getKeyCode(attribute);
event.code = attribute;
// deprecated / removed from the Web Standards
event.which = keyCode;
event.keyCode = keyCode;
}
return event;
}, {});
const event = (attributes || '').split('+').reduce((event, attribute) => {
if (validModifiers.indexOf(attribute) > -1) {
attribute = attribute === 'cmd' ? getCmdKey() : attribute;
event[`${attribute}Key`] = true;
} else if (validMouseButtons.indexOf(attribute) > -1) {
event.button = getMouseCode(attribute);
} else {
event.keyCode = getKeyCode(attribute);
}
return event;
}, {});
export default function(app, duration) {
const keyCode = getKeyCode('F3');
triggerEvent(document, 'keyup', {
keyCode,
which: keyCode,
altKey: true,
ctrlKey: true,
shiftKey: true
});
return delay(duration);
}
const triggerKeyEvent = function triggerKeyEvent(eventType, rawCode, element) {
const event = new Event(eventType);
const parts = rawCode.split('+');
const [code] = parts.filter((part) => !validModifiers.includes(part));
const modifiers = parts.filter((part) => part !== code);
const properties = modifiers.reduce((properties, modifier) => {
modifier = modifier === 'cmd' ? getCmdKey() : modifier;
properties[`${modifier}Key`] = true;
return properties;
}, {});
assign(event, { code, keyCode: getKeyCode(code) }, properties);
(element || document).dispatchEvent(event);
};