document.addEventListener('keydown', function(e) {
console.log( 'keydown:' + (e.code ? e.code : e.key));
});
document.addEventListener('keyup', function(e) {
console.log( 'keyup:' + (e.code ? e.code : e.key));
});
document.addEventListener('keypress', function(e) {
console.log( 'keypress:' + (e.code ? e.code : e.key) );
});
var e = new KeyboardEvent("keydown", {bubbles : true, cancelable : true, key : "Control", code : "ControlLeft", ctrlKey : true});
document.dispatchEvent(e);
e = new KeyboardEvent("keydown", {bubbles : true, cancelable : true, key : "B", char : "B", ctrlKey : true});
document.dispatchEvent(e);
e = new KeyboardEvent("keypress", {bubbles : true, cancelable : true, code : "KeyB", ctrlKey : true});
document.dispatchEvent(e);
e = new KeyboardEvent("keyup", {bubbles : true, cancelable : true, key : "B", char : "B", ctrlKey : true});
document.dispatchEvent(e);
e = new KeyboardEvent("keyup", {bubbles : true, cancelable : true, key : "Control", code : "ControlLeft", ctrlKey : true});
document.dispatchEvent(e);
, если это не работает, метод dispatchEvent может быть заблокирован. Посмотрите на это , если оно не работает