DEV Community

Nevin Katz
Nevin Katz

Posted on

2

Handling touch and mouse events with JavaScript

Since I was young programming on a Commodore 128, I have learned a fair bit of programming by building games.

One particular interest I have is building dungeon crawlers and maze games. Recently I have been learning more about how to handle both mouse events and touch events in a JavaScript maze game I have been building.

While working on fine-grained controls that rely on when touch or click events start and end, I learned about how to get a set of button controls to respond to both touch events and mouse events without having both fire at the same time.

If you are building games or apps and interested in solving similar play control problems, check out my article on separating mouse and touch events, recently published on CodeX. I break down the problem I ran into and have a few code snippets that convey how I solved it.

Thanks for reading!

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️