키 이벤트 (누름)를 크롬 53에서 시뮬레이트하려고합니다. I에 유래에서 발견 모든 솔루션은자바 스크립트 - Chrome에서 키 이벤트 시뮬레이트 53
내 목표는 keyCode
을 유도 할 수있는 기능을 가지고있다 .. 작동하지 않는 것 같습니다과 함께 키 누름을 시뮬레이션 - 순수 JS가
function keyPressSimulate(keyCode) {...?}
필요합니다 나는 이미 시도
코드 샘플 :
Node.prototype.fire=function(type,options){
var event=new CustomEvent(type);
for(var p in options){
event[p]=options[p];
}
this.dispatchEvent(event);
}
document.fire("keyup",{ctrlKey:true,keyCode:90,bubbles:true})
또 다른 하나
그리고 :
var e = new KeyboardEvent("keydown", {bubbles : true, cancelable : true, key : "Q", shiftKey : true});
global.document.dispatchEvent(e);
그리고 :
presskey: function(k) {
var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent";
keyboardEvent[initMethod](
"keydown",
true, // bubbles oOooOOo0
true, // cancelable
window, // view
false, // ctrlKeyArg
false, // altKeyArg
false, // shiftKeyArg
false, // metaKeyArg
k,
0 // charCode
);
global.document.activeElement.dispatchEvent(keyboardEvent);
}
많은 가능한 해결책을 찾았습니다. http://stackoverflow.com/questions/10455626/keydown-simulation-in-chrome-fires-normally-but-not-the-correct-key me –
해결책은 순수한 js이어야합니다. –
무례한 것은 아닙니다.하지만 이미 노력한 코드 샘플을 추가 할 때까지 아무도 도움을주지 않을 것입니다 ... – evolutionxbox