Skip to content

How to manually trigger key enent by js? #17729

Closed Answered by chenxuuu
chenxuuu asked this question in Q&A
Discussion options

You must be logged in to vote

I solved this, it need to focus on the container div inside of ruffle player's shadowRoot, not the player

var player = document.getElementById('swf_player').children[0];

var playerContainer = player.shadowRoot.querySelector("#container");
var pointerEvent = new PointerEvent("pointerdown");
playerContainer.dispatchEvent(pointerEvent);

var gameEvent = new KeyboardEvent('keydown', {
    key:"ArrowRight",code: "ArrowRight", keyCode: 39, bubbles: true, 
});
player.dispatchEvent(gameEvent);

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@torokati44
Comment options

Answer selected by chenxuuu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants