Krombik / keysender

Node.js Desktop Automation for Windows.
MIT License
75 stars 6 forks source link

Save image with sharp #6

Closed ch3rn1k closed 1 year ago

ch3rn1k commented 1 year ago

Hello! Awesome lib, thank you! Can you tell me how can I save capture() with sharp? Everytime I'm getting black image...

import sharp from 'sharp';
import { Hardware } from 'keysender';

const desktop = new Hardware(0);

const saver = () => {
  const screen = desktop.workwindow.capture();
  sharp(screen.data, {
    raw: {
      width: screen.width,
      height: screen.height,
      channels: 4
    }
  }).toFile(...);
};

saver();

Screenshoot 1664009799183 Screenshoot 1664009808044

ch3rn1k commented 1 year ago

Looks like problem in capture(), it returns to me strange things: I used toString to see what is inside like this Buffer.from(screen.data).toString('base64')

UPD: Used colorAt and it return everytime ffffff. Am I doing something wrong?

image

ch3rn1k commented 1 year ago

Found that problem with const desktop = new Hardware(0);. When using 0 it always black, but if I set something like const desktop = new Hardware('Windows.UI.Core.CoreWindow'); it works fine. How can i fix using zero? Thanks

Krombik commented 1 year ago

use just const desktop = new Hardware();

ch3rn1k commented 1 year ago

use just const desktop = new Hardware();

Well yea, that works, thanks!