emscripten-core / emscripten-core/emscripten
Attach event listeners to the canvas rather than the window object
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Hi!
I'm fairly new to messing with WebAssembly, so sorry for any inacuracy or misunderstanding on my part.
I compiled a fairly simple raylib game with emscripten and tried emedding it in a blog article. Everything worked fine, except that the game was grabbing *all* browser events, so when ie scrolling the page up or down with the arrow keys, the game would also respond to the same inputs, which quickly got annoying.
Digging in, I found out that the js wrapper generated was attaching some event listeners to the window object, and some others to the canvas (see https://github.com/emscripten-core/emscripten/blob/926047d8c01101a0558ea501ed54a4e76af43a37/src/lib/libglfw.js#L1432). I attached them all to the canvas and this fixed my issue.
Once again, I'm pretty clueless about this environment, so I don't want to presume there's not a good reason why those get set on the window, but I thought I'd mention it in case my hack is considered acceptable. And if not, is there some cleaner way to override the behaviour without messing with the generated wrapper ?
Thanks,
Raphi.
Contributor guide
Assessment
This issue has not been assessed yet.