-
-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Add KeyboardScope option #1512
Labels
enhancement
Label applied to enhancements or improvements to existing features
proposal
Applied to issues that are a proposal for an implementation
Comments
kamranayub
added
the
enhancement
Label applied to enhancements or improvements to existing features
label
Apr 28, 2020
5 tasks
kamranayub
added
the
proposal
Applied to issues that are a proposal for an implementation
label
Apr 30, 2020
This issue hasn't had any recent activity lately and is being marked as stale automatically. |
github-actions
bot
added
the
stale
This issue or PR has not had any activity recently
label
Dec 27, 2020
github-actions
bot
removed
the
stale
This issue or PR has not had any activity recently
label
Jan 22, 2023
eonarheim
added a commit
that referenced
this issue
Jun 14, 2023
5 tasks
Workaround for itch.io games and codesandbox.io Add this snippet engine.start().then(() => {
window.focus();
}); |
eonarheim
added a commit
that referenced
this issue
Jun 14, 2023
This PR adds a new engine option (which is on by default) to grab the window focus when hosted in an iframe. This allows keyboard events to work by default. Confirmed on itch.io https://eonarheim.itch.io/iframe-test Closes #1512
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
Label applied to enhancements or improvements to existing features
proposal
Applied to issues that are a proposal for an implementation
Context
There are some issues using Excalibur in cross-origin iframes, see #1294 and #1510
What happens is that event listeners cannot listen on the top frame. In order to provide a fallback, we specific
window
as the target to listen to key events but that doesn't work either (according to our code, it never did).There are some approaches we can try that will enable keyboard events when embedding cross-origin, which is by targeting the canvas or an element surrounding the canvas.
Proposal
Option 1: Try to use tabindex and focus
According to this SO answer it should be possible to attach listeners if the canvas has
tabindex="1"
and is in focus. I couldn't get this to work, though, but I didn't have time to explore it much.Option 2: Use a wrapping element
The other way is by targeting an element that wraps the canvas. A
<div>
or a<span>
may work (I like the inline element since it should wrap to the bounds of the canvas better).This does work and I got it to work by adding a new option to allow passing in the element ID or element to target keyboard events on. In Storybook, this is
document.getElementById('root')
.However, I thought it may be better to implement the same idea we have for
PointerScope
and do aKeyboardScope
and automatically generate the wrapping capture elementThis presents some issues though, when the canvas is detached from the DOM. It can't be re-parented to be under the capture element.
Ideally, this keyboard initialization logic would run when the game boots up in the DOM for the first time and I got close but not quite in my spike of doing this.
The text was updated successfully, but these errors were encountered: