Skip to content

Attach event listeners to the canvas rather than the window object #26971

@raphigaziano

Description

@raphigaziano

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

window.addEventListener('gamepadconnected', GLFW.onGamepadConnected, true);
). 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions