Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xan105/node-win-screen-resolution
Get the current and all available screen resolution on Windows
https://github.com/xan105/node-win-screen-resolution
native-module nodejs resolution screen windows
Last synced: 2 months ago
JSON representation
Get the current and all available screen resolution on Windows
- Host: GitHub
- URL: https://github.com/xan105/node-win-screen-resolution
- Owner: xan105
- License: mit
- Created: 2020-08-04T09:52:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-22T05:00:21.000Z (6 months ago)
- Last Synced: 2024-10-17T12:56:06.776Z (3 months ago)
- Topics: native-module, nodejs, resolution, screen, windows
- Language: JavaScript
- Homepage:
- Size: 8.61 MB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
About
=====A NAPI Native C++ addon to get the current and all available screen resolution on Windows (DPI Aware).
Example
=======```js
import {
getCurrentResolution,
getAvailableResolution
} from "win-screen-resolution";console.log(getCurrentResolution());
//{ width: 1920, height: 1080 }console.log(getAvailableResolution());
/*
[
{ width: 1920, height: 1080 },
{ width: 1768, height: 992 },
{ width: 1680, height: 1050 },
{ width: 1600, height: 1024 },
...
]
*/
```You may want the raw data which has more information such as the refresh rate:
```js
import {
getCurrentDisplayMode,
getAvailableDisplayMode
} from "win-screen-resolution";console.log(getCurrentDisplayMode());
//{ width: 1920, height: 1080, hz: 60, color: 32 }console.log(getAvailableDisplayMode());
/*
[
{ width: 640, height: 480, hz: 59, color: 32 },
{ width: 640, height: 480, hz: 60, color: 32 },
{ width: 640, height: 480, hz: 75, color: 32 },
{ width: 720, height: 480, hz: 60, color: 32 },
...
]
*/```
Installation
============```
npm install win-screen-resolution
```🚀 x86, x64 and arm64 prebuilt binary provided.
Force compiling:
```
npm install win-screen-resolution --build-from-source
```You will need C/C++ build tools and Python 3.x (node-gyp) to build this module.
API
===⚠️ This module is only available as an ECMAScript module (ESM) starting with version 2.0.0.
Previous version(s) are CommonJS (CJS) with an ESM wrapper.**DPI Awareness**
The following exports are DPI aware meaning that their results won't change with different DPI scalor factor.
Please note that support for DPI awareness on Windows 7/8 was removed in 3.x. If you need it use previous version.## Named export
#### `getCurrentDisplayMode(): object`
Get the current **primary display** video mode as follows:
```ts
{
width: number, //Horizontal resolution
height: number, //Vertical resolution
hz: number, //Refresh rate
color: number //Color depth in bits/pixel
}
```❌ Will throw on unexpected error.
#### `getAvailableDisplayMode(): object[]`
Get all available display video mode from the current display device on which the calling thread is running as follows:
```ts
[
{
width: number, //Horizontal resolution
height: number, //Vertical resolution
hz: number, //Refresh rate
color: number //Color depth in bits/pixel
}
]
```❌ Will throw on unexpected error.
#### `getCurrentResolution(): object`
alias: `current()` _backward compatibility_
Get the current **primary display** screen resolution as follows:
```ts
{
width: number,
height: number
}
```This is a short hand to `getCurrentDisplayMode()`
❌ Will throw on unexpected error.
#### `getAvailableResolution(): object[]`
alias: `list()` _backward compatibility_
Get all available screen resolution from the current display device on which the calling thread is running sorted _from highest to lowest_ as follows:
```ts
[
{
width: number,
height: number
}
]
```💡 Available screen resolution below 800x600 are ignored because of Windows 10 min display resolution requirement.
This is a short hand to `getAvailableDisplayMode()`
❌ Will throw on unexpected error.