Skip to content

Refactor input handling and add windowBlurred event #135

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ormaq
Copy link
Contributor

@ormaq ormaq commented Aug 7, 2025

Introduces the 'windowBlurred' event to the core event list and refactors input event handling for improved pointer, mouse, and touch management. Adds a resetInput method, uses a Set for pressed mouse buttons, ensures pointer capture/release, and streamlines event listener attachment for better reliability and maintainability.

  • windowBlurred
    This is an event that is called when we tab out of the current browser tab. Useful if say we are doing something complex and want to pause the game or stop logic until the user returns.

  • resetInput
    This is another feature that is more of a quality of life thing. We can at anytime remove all input currently held. Pairs nicely with windowBlurred.

I reworked the logic for mouse presses and specifically events. Before hand there was some odd logic with holding mouse 1 or 2 and pressing the other button. For example if you hold mouse 1 and tap mouse 2 we dont release mouseIsPressed. But if you hold mouse 2 then tap mouse 1 we do release!
So the logic here makes the mouse down parity p5. Where if you hold 2 mouse buttons releasing 1 causes mouseIsPressed to be false.
Also added some small touch ups.
Also updated _updateTouches to be more modern js code 😄

ormaq added 2 commits August 7, 2025 11:50
Introduces the 'windowBlurred' event to the core event list and refactors input event handling. Add a resetInput method, uses a Set for pressed mouse buttons, rework pointer capture to behave the same as p5, and updates event listener attachment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant