Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Scaling issues: screen functions broken #249

Closed
1 of 3 tasks
kgallimore opened this issue Jul 16, 2021 · 4 comments · Fixed by nut-tree/libnut-core#86
Closed
1 of 3 tasks

Windows Scaling issues: screen functions broken #249

kgallimore opened this issue Jul 16, 2021 · 4 comments · Fixed by nut-tree/libnut-core#86
Assignees
Labels
bug Something isn't working

Comments

@kgallimore
Copy link

Version
1.7.0
Short overview
Windows Scaling is affecting multiple screen functions, not returning right height/width, messing with screen capture, screen find

Issue occurs on

  • Virtual machine
  • Docker container
  • Dev/Host system

Detailed error description
console.log(screen.height()); = Promise { 864 }
Actual height: 2160
It is affected by windows scaling(Set to 250%, 864*2.5 = 2160)

Set scaling to 100%:
console.log(screen.height()); = Promise { 2160 }

screen.find is also broken, it doesn't find matches, and the incorrect guesses highlight boxes are also positioned erratically.

screen.capture only captures a portion of the screen based off the scaling number.

Steps to reproduce error

Additional content

Please provide any (mandatory) additional data to reproduce the error (Dockerfiles etc.)

@kgallimore
Copy link
Author

My placeholder workaround in case anyone is coming across the same issue. You need to expose the included opencv installation and then add robotjs and jimp.

const cv = require("opencv4nodejs-prebuilt");
const robot = require("robotjs");
const Jimp = require("jimp");
async function findQuitTemp(templateImage, targetCoefficient = 0.9) {
  let pic = robot.screen.capture();
  const image = new Jimp(pic.width, pic.height);
  let pos = 0;
  image.scan(0, 0, image.bitmap.width, image.bitmap.height, (x, y, idx) => {
    image.bitmap.data[idx + 2] = pic.image.readUInt8(pos++);
    image.bitmap.data[idx + 1] = pic.image.readUInt8(pos++);
    image.bitmap.data[idx + 0] = pic.image.readUInt8(pos++);
    image.bitmap.data[idx + 3] = pic.image.readUInt8(pos++);
  });
  await image.writeAsync(`${__dirname}/tempresolve.png`);
  const target = await cv.imreadAsync(`${__dirname}/tempresolve.png`);
  const template = await cv.imreadAsync(`${__dirname}/${templateImage}`);

  // Match template (the brightest locations indicate the highest match)
  const matched = target.matchTemplate(template, 5);
  return matched.minMaxLoc().maxVal >= targetCoefficient;
}

@s1hofmann s1hofmann self-assigned this Aug 13, 2021
@s1hofmann s1hofmann added the bug Something isn't working label Aug 13, 2021
@s1hofmann
Copy link
Member

s1hofmann commented Aug 13, 2021

@kgallimore Just to make sure: I started digging into this issue and gave your workaround script a run.

Are you sure it really solves the problem? It actually captures the exact same portion of the screen as screen.capture() does? As for search input this workaround is just as affected as nut.js.

The tweaked matching coefficient and a single search run might lead to a different result, tho.

@kgallimore
Copy link
Author

@kgallimore Just to make sure: I started digging into this issue and gave your workaround script a run.

Are you sure it really solves the problem? It actually captures the exact same portion of the screen as screen.capture() does? As for search input this workaround is just as affected as nut.js.

The tweaked matching coefficient and a single search run might lead to a different result, tho.

So it only captured a portion in a test script, but when I used it within my electron application it found the whole screen? But yea as a standalone my work around seems to not work either. I'm actually not sure what's going on right now. The biggest difference (besides being inside an electron application) I can think of is what node version is being used.

@s1hofmann
Copy link
Member

I haven’t checked this yet, but maybe Electron is, in contrast to the plain node executable, scale aware.

s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Nov 9, 2021
…nt to always capture the full screen content even with scaling applied
s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Nov 9, 2021
s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Nov 9, 2021
(nut-tree/nut.js#249) Enable DPI awareness when fetching screen conte…
s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Dec 11, 2021
* (#47) Deleted src/buffer_finalizer.h

* (#47) Switched to using Buffer::Copy

* Fix for screen highlight window minimized intead close

* Create LICENSE.md

* Add Helper Methods for calculating the required absolute position on the screen

* Refactor moveMouse to use SendInput for absolute position movements on windows

* Indentation

* Add Coord constant

* Squash x and y coord methods
Make Absolute coord calculation return MMPoint

* Call coord calculator with MMPoint

* Correct Types and Return values

* Import for getMainDisplaySize

* Bugfix for lost co-ordinate precision

* (nut-tree/nut.js#249) Enable DPI awareness when fetching screen content to always capture the full screen content even with scaling applied

* (nut-tree/nut.js#249) Refactor scale calculation to work correctly with custom regions

* (nut-tree/nut.js#306) Specify supported os and cpu in package.json to enable Apple Silicon

* Remove scan code block

* Release/v2.1.3 (#88)

* Update changelog for v2.1.3

* Release v2.1.3

Co-authored-by: Gyula Madarasz <[email protected]>
Co-authored-by: Reiss Cashmore <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants