kapetan / win-mouse

Mouse tracking for Windows
54 stars 20 forks source link

Reported coordinates on high/variable dpr displays? #13

Open patrickhlauke opened 6 years ago

patrickhlauke commented 6 years ago

We've been having to compensate for situations where a screen isn't set to 100% scaling by dividing the x and y by window.devicePixelRatio (see https://github.com/ThePacielloGroup/CCAe/commit/739de8f284a37cf858e533706b443cbb2f74b892). Wondering if there's a cleaner way that this package could do this out of the box?

poiru commented 5 years ago

@patrickhlauke On Electron 3 and later, you should be able to use screen.screenToDipPoint like so:

const screen = require('electron').screen;
mouse.on('move', (x, y) => {
 console.log('move pixels:', {x, y}, 'dip:', screen.screenToDipPoint({x, y}));
});