Hi all, I put my project into iframes on webpage. When I am using the keyboard and specifically its arrows - its problem. When I press the right or left arrow key on my keyboard, all is good. When I press the up or down arrow, the project action is performed. The problem is that the main browser window also reacts to the arrows keys. The whole page will move me up or down. How to solve this so that I can use the arrows keys?
Is the iframe focused when you press the arrow keys? Have you added preventDefault to the key handlers?
3 Likes
I am using this code below. Need to add something? The iFrame is selected, has focus. The up arrow key code is executed 2x. First time properly, second time unnecessarily, when the whole page starts to scroll up.
scene.actionManager = new BABYLON.ActionManager(scene);
scene.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnKeyDownTrigger, (evt) => {
if (evt.sourceEvent.key == “ArrowUp”) {
// DO some action
}
}
I’m confused, you marked my answer as solution, but did it solve your issue? Did you try adding preventDefault…?
Your tip: “preventDefault” is solution of my problem
1 Like