Use the Monitor class to interact with physical displays. You can retrieve all available monitors using Monitor.all() or find a specific monitor based on screen coordinates using Monitor.fromPoint(x, y).
Once you have a Monitor instance, you can capture its content using either captureImageSync() for synchronous execution or captureImage() for an asynchronous Promise-based approach.
const { Monitor } = require('node-screenshots');
const fs = require('fs');
// Get monitor at specific coordinates
let monitor = Monitor.fromPoint(100, 100);
if (monitor) {
// Synchronous capture
let image = monitor.captureImageSync();
fs.writeFileSync(`${monitor.id()}-sync.png`, image.toPngSync());
// Asynchronous capture
monitor.captureImage().then((data) => {
fs.writeFileSync(`${monitor.id()}.jpeg`, data.toJpegSync());
});
}
// List all monitors and their properties
const monitors = Monitor.all();
monitors.forEach((item) => {
console.log(
'Monitor:',
item.id(),
item.name(),
[item.x(), item.y(), item.width(), item.height()],
item.rotation(),
item.scaleFactor(),
item.frequency(),
item.isPrimary()
);
});