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

Get Screen Dimensions #25

Closed
ThisIsJohnBrown opened this issue Apr 24, 2015 · 8 comments
Closed

Get Screen Dimensions #25

ThisIsJohnBrown opened this issue Apr 24, 2015 · 8 comments

Comments

@ThisIsJohnBrown
Copy link

Having screen dimensions would be great for calculating where on the screen the mouse is or should be.

This could be returned as a new call in screen or returned with the object from getMousePos() so you would have x, y, width, and height parameters.

Another possibility is passing into getMousePos({percent:true}) and have it return 2 percentages rather than a fixed location { x: 50.44, y: 22.34 }
.

@octalmage
Copy link
Owner

I think I'll create a new method for getting the screen size so it's not slowed down by getting the mouse position. The internal C function getMainDisplaySize() does what you want, it will be very easy to expose it to Node.js (with a new name).

I'll try to get this added tonight!

@octalmage
Copy link
Owner

Sorry, thought I replied to this. I added getScreenSize:

var robot = require("robotjs");

var screen = robot.getScreenSize();

console.log(screen.width + "x" + screen.height);

I released RobotJS v0.1.2 with this function, update and let me know how it works!

@ThisIsJohnBrown
Copy link
Author

Perfect! Thank you, @octalmage!

@octalmage
Copy link
Owner

@ozkr0124
Copy link

Good day.

the function to obtain the screen size in macOS does not operate, the result it shows is 0 in width as in height

`var robot = require("robotjs");

// Speed up the mouse.
robot.setMouseDelay(10);

var twoPI = Math.PI * 2.0;
var screenSize = robot.getScreenSize();
console.log(screenSize);
var height = 768;
var width = 1366;

for (var x = 0; x < width; x++) {
y = height * Math.sin((twoPI * x) / width) + height;
robot.moveMouse(x, y);
}`

@data987
Copy link

data987 commented Mar 11, 2020

I've got the same issue! Does somebody know how to solve this?

@selimgr
Copy link

selimgr commented Mar 18, 2020

Same issue... any fixes?

@stephanbogner
Copy link

If I use NVM to switch to Node v10.23.1 it works. (I use MacOS Catalina 10.15.7)
So apparently there was a change in NodeJS itself that broke robot.getScreenSize() and thus also mouse clicks? 🤔

Note: I didn't investigate at which version it started to break, v10.23.1 was just the one I already had in NVM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants