-
I test many way, but no one works var player = document.getElementById('swf_player').children[0];
player.focus();
// left arrow down
var leftKeyDown = new KeyboardEvent('keydown', {
bubbles: true,
cancelable: true,
keyCode: 37,
which: 37
});
player.dispatchEvent(leftKeyDown);
var leftKeyUp = new KeyboardEvent('keyup', {
bubbles: true,
cancelable: true,
keyCode: 37,
which: 37
});
player.dispatchEvent(leftKeyUp); so which way can do this? I want to add virtual keypad for mobile phone or other touch screen device |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
See this answer: #6952 (comment) You need to make Ruffle think it has focus by simulating a PointerEvent first. |
Beta Was this translation helpful? Give feedback.
-
@n0samu sadly it doesn't work, only work after I click the player manually |
Beta Was this translation helpful? Give feedback.
-
I solved this, it need to focus on the 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); |
Beta Was this translation helpful? Give feedback.
I solved this, it need to focus on the
container div
inside of ruffle player's shadowRoot, not the player