npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

screentap

v0.0.15

Published

Get event on current active screen change

Downloads

467

Readme

ScreenTap.js

ScreenTap.js is a Node.js addon library that allows you to detect mouse/tap events on the screen/display. It currently supports both macOS and Windows. The library triggers events that may occur on different screens and provides the displayId of the currently active screen (screen where the event occured), such as mouse up/down events and foreground window changes/moves (currently only supported on Windows).

Installation

You can install ScreenTap.js using npm:

npm install screentap

API Usage

ScreenTap.js exports a ScreenTap class that extends EventEmitter. You can use it to listen for screen change events.

Here's a basic example:

import ScreenTap from "screentap";

const screenTap = new ScreenTap();

screenTap.on("foregroundWindowUpdated", ({ eventName, displayId }) => {
	console.log("Foreground window updated ", displayId);
});
screenTap.on("leftMouseDown", ({ eventName, displayId }) => {
	console.log("Left mouse button down", displayId);
});
screenTap.on("leftMouseUp", ({ eventName, displayId }) => {
	console.log("Left mouse button up", displayId);
});
screenTap.on("rightMouseDown", ({ eventName, displayId }) => {
	console.log("Right mouse button down", displayId);
});
screenTap.on("rightMouseUp", ({ eventName, displayId }) => {
	console.log("Right mouse button up", displayId);
});

screenTap.startScreenTapListener();

setTimeout(() => {
	screenTap.stopScreenTapListener();
}, 10_000);

API Reference

startScreenTapListener()

Starts the screen tap listener. This should be called to start receiving the events in your subscribed listeners.

on(event: TScreenChangeEvent, listener: (event: IScreenTapEventResult) => void): this

Subscribes to a screen change event. The listener callback is called with an IScreenTapEventResult object whenever the event occurs.

off(event: TScreenChangeEvent, listener: (event: IScreenTapEventResult) => void): this

Unsubscribes from a screen change event. The listener callback will no longer be called for the event.

stopScreenTapListener()

Stops the screen tap listener. This should be called when you no longer want to receive events.

IScreenTapEventResult

This interface represents the object that is passed to event listeners when a screen change event occurs.

eventName: TScreenChangeEvent

This property is a string that indicates the type of the event that occurred. It can have one of the following values:

  • leftMouseDown: Triggered when the left mouse button is pressed down.
  • leftMouseUp: Triggered when the left mouse button is released.
  • rightMouseDown: Triggered when the right mouse button is pressed down.
  • rightMouseUp: Triggered when the right mouse button is released.
  • foregroundWindowUpdated (Windows only): Triggered when the foreground window is updated. This event is currently only supported on Windows.

displayId: number

The display where the event occurred. If the display cannot be determined, the displayId will be -1.

EventEmitter API

Since ScreenTap extends EventEmitter, all the APIs of Node.js's EventEmitter are available. This includes methods like addListener, removeListener, removeAllListeners, once, and so on.

Here's an example of using the once method to listen for a single leftMouseDown event:

import ScreenTap from "screentap";

const screenTap = new ScreenTap();

screenTap.once("leftMouseDown", (event) => {
	console.log("Left mouse button pressed", event);
});

screenTap.startScreenTapListener();

In this example, the listener is automatically removed after it is called once, so it will only log the first leftMouseDown event.

For more information about the EventEmitter API, see the Node.js documentation.

Contributing

Contributions are welcome! Please submit a pull request or create an issue to propose changes or report bugs.

License

ScreenTap.js is licensed under the MIT License. See the LICENSE file for more details.