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

windows-ss

v1.0.1-xx

Published

[![npm version](https://badge.fury.io/js/windows-ss.svg)](https://badge.fury.io/js/windows-ss)

Downloads

3

Readme

windows-ss

npm version

Take screenshots quickly on Windows by communicating directly with native API's.

Did I mention that it's DPI aware too?

Benchmark

Using this repo. The numbers below were taken over 1000 runs, each at 2560x1440*, outputing bmp.

| Library | Save to buffer | Save to file | | ------------------ | -------------- | ------------ | | windows-ss | 52ms | 51ms | | screenshot-desktop | 152ms | 141ms | | desktop-screenshot | n/a | 63ms** |

* Except for desktop-screenshot, it ran at 1706x960 as it's DPI unaware.

** Times are relative to lower resolution of 1706x960. If interpolated back to 1440p according to a DPI of 1.5, 63 * (1.5 ^ 2) = 141ms

Installation

npm i windows-ss

IMPORTANT: You'll need .NET 4.5 or .NET Core installed, as this library depends on edge-js. Refer here for more info regarding installation.

Usage

import { capturePrimaryMonitor } from 'windows-ss';

await capturePrimaryMonitor({    
    // The format of the returned Buffer & saved file.
    format: 'png',
    
    // How much to carve off the edges. (Left, Top, Right, Bottom)
    crop: {
        left: 0,
        top: 0,
        right: 0,
        bottom: 0,
    },
    
    // The bounds where the screen will be captured. (Left, Top, Right, Bottom)
    bounds: {
        left: 0,
        top: 0,
        right: 0,
        bottom: 0,
    },
    
    // The file the screenshot will be saved to.
    save: './ss.png', 
});

API

Table of Contents

Methods

getMonitorInfos

getMonitorInfosSync

Returns information about the the currently connected monitors.

Parameters
  • n/a
Returns
Throws
  • n/a
Example
import { getMonitorInfos, getMonitorInfosSync } from 'windows-ss';

await getMonitorInfos();
getMonitorInfosSync();
/*
	// Example output
    [
      {
        monitor: { left: 0, top: 0, right: 2560, bottom: 1440 },
        workArea: { left: 0, top: 0, right: 2560, bottom: 1380 },
        deviceName: '\\\\.\\DISPLAY1'
      },
      {
        monitor: { left: 304, top: -1080, right: 2224, bottom: 0 },
        workArea: { left: 304, top: -1080, right: 2224, bottom: -40 },
        deviceName: '\\\\.\\DISPLAY2'
      }
    ]
*/

captureMonitorByIndex

captureMonitorByIndexSync

Captures a screenshot of the monitor matching the device index.

Parameters
  • deviceIndex: number
    • Index of monitor according to Windows.
  • (Optional) config: Configuration
    • Additional options for capturing the screenshot.
Returns
  • Promise<Buffer | null> —— Buffer | null
    • The binary image data of the screenshot, with the format specified in options.format. null is returned instead if save was passed into the config parameter.
Throws
Example
import { captureMonitorByIndex, captureMonitorByIndexSync, getMonitorInfos } from 'windows-ss';

const monitorInfos = await getMonitorInfos();

await captureMonitorByIndex(monitorInfos.length - 1);
captureMonitorByIndexSync(0);

captureMonitorByName

captureMonitorByNameSync

Captures a screenshot of the monitor matching the device name.

Parameters
  • deviceName: string
    • Name of monitor according to Windows.
  • (Optional) config: Configuration
    • Additional options for capturing the screenshot.
Returns
  • Promise<Buffer | null> —— Buffer | null
    • The binary image data of the screenshot, with the format specified in options.format. null is returned instead if save was passed into the config parameter.
Throws
Example
import { captureMonitorByName, captureMonitorByNameSync, getMonitorInfos } from 'windows-ss';

const monitorInfos = await getMonitorInfos();

await captureMonitorByName(monitorInfos[0].deviceName);
captureMonitorByNameSync(String.raw`\\.\DISPLAY1`);

capturePrimaryMonitor

capturePrimaryMonitorSync

Captures a screenshot of the primary monitor.

Parameters
  • (Optional) config: Configuration
    • Additional options for capturing the screenshot.
Returns
  • Promise<Buffer | null> —— Buffer | null
    • The binary image data of the screenshot, with the format specified in options.format. null is returned instead if save was passed into the config parameter.
Throws
Example
import { capturePrimaryMonitor, capturePrimaryMonitorSync } from 'windows-ss';

await capturePrimaryMonitor();
capturePrimaryMonitorSync();

captureWindowByTitle

captureWindowByTitleSync

Captures a screenshot of the window matching the title.

Parameters
  • title: string
    • Title of window.
  • (Optional) config: Configuration
    • Additional options for capturing the screenshot.
Returns
  • Promise<Buffer | null> —— Buffer | null
    • The binary image data of the screenshot, with the format specified in options.format. null is returned instead if save was passed into the config parameter.
Throws
Example
import { captureWindowByTitle, captureWindowByTitleSync } from 'windows-ss';

await captureWindowByTitle('Task Manager');
captureWindowByTitleSync('Notepad');

captureActiveWindow

captureActiveWindowSync

Captures a screenshot of the currently active/focused window.

Parameters
  • (Optional) config: Configuration
    • Additional options for capturing the screenshot.
Returns
  • Promise<Buffer | null> —— Buffer | null
    • The binary image data of the screenshot, with the format specified in options.format. null is returned instead if save was passed into the config parameter.
Throws
Example
import { captureActiveWindow, captureActiveWindowSync } from 'windows-ss';

await captureActiveWindow();
captureActiveWindowSync();

Interfaces

Configuration

Contains options that can be provided by the user when taking a screenshot.

Properties
  • (Optional) format: string — The format of the returned buffer & saved file.

    • Default'png'
    • Valid Values
      • 'png'
      • 'jpg'
      • 'jpeg'
      • 'bmp'
      • 'emf'
      • 'exif'
      • 'gif'
      • 'icon'
      • 'tiff'
      • 'wmf'
  • (Optional) crop: PlainRectangle — How much to carve off the edges.

  • (Optional) bounds: PlainRectangle — The bounds where the screen will be captured.

  • (Optional) save: string — The path to where the screenshot will be saved to.

    • Note: If this property is not provided, the screenshot is simply returned as a Buffer.

MonitorInfo

Contains a description of a monitor.

Properties
  • monitor: PlainRectangle — The resolution of the entire monitor.
  • workArea: PlainRectangle — The resolution of the entire monitor excluding the taskbar.
  • deviceName: string — The device name of the monitor.

PlainRectangle

Contains properties to form a plain rectangle.

Properties
  • left: number — The left edge of the rectangle.

    • IMPORTANT: This must be of int type, meaning no decimals. Else, it will fail applying configuration.

  • top: number — The top edge of the rectangle.

    • IMPORTANT: This must be of int type, meaning no decimals. Else, it will fail applying configuration.

  • right: number — The right edge of the rectangle.

    • IMPORTANT: This must be of int type, meaning no decimals. Else, it will fail applying configuration.

  • bottom: number — The bottom edge of the rectangle.

    • IMPORTANT: This must be of int type, meaning no decimals. Else, it will fail applying configuration.

Errors

NoMatchError

Thrown when no match can be found with the provided arguments.

Extends
Properties
  • (Inherited) paramName: string
  • (Inherited) name: string
  • (Inherited) stack: string
  • (Inherited) raw: CSException

InvalidArgumentCountError

Thrown when an invalid amount of arguments were provided.

Extends
Properties
  • (Inherited) paramName: string
  • (Inherited) name: string
  • (Inherited) stack: string
  • (Inherited) raw: CSException

InvalidConfigurationError

Thrown when an invalid Configuration object was provided.

Extends
Properties
  • (Inherited) paramName: string
  • (Inherited) name: string
  • (Inherited) stack: string
  • (Inherited) raw: CSException

(Internal) CSArgumentError

Based on C#'s ArgumentException.

Extends
Properties
  • paramName: string
  • (Inherited) name: string
  • (Inherited) stack: string
  • (Inherited) raw: CSException

(Internal) CSError

Based on C#'s SystemException.

Extends
  • ClientError
    • An internal wrapper for Error
Properties
  • raw: CSException
    • The InnerException property of the raw Error object thrown by edge-js
  • (Inherited) name: string
  • (Inherited) stack: string

Contributing

All contributions are welcome. File an issue if you find something wrong, & a pull request if you can fix it.

License

MIT.