简体   繁体   English

Java Awt鼠标位置坐标计算

[英]Java Awt mouse position coordinates calculation

I can get the Position of the cursor by the following code, but I don`t understand how the coordinates are calculated.我可以通过下面的代码得到光标的位置,但是我不明白坐标是如何计算的。

MouseInfo.getPointerInfo().getLocation();

If the mouse is in the right top corner the coordinates are "java.awt.Point[x=2047,y=0]", but the resolution of my screen is 2560 x 1440 so I expected the coordinates to be [x=2560,y=0].如果鼠标位于右上角,则坐标为“java.awt.Point[x=2047,y=0]”,但我的屏幕分辨率为 2560 x 1440,因此我预计坐标为 [x=2560 ,y=0]。

So how are these coordinated calculated?那么这些协调是如何计算的呢?

When I try something like:当我尝试类似的事情时:

while(true){
    System.out.println(MouseInfo.getPointerInfo().getLocation());
    Thread.sleep(1000);
}

Its printing out:它的打印输出:

java.awt.Point[x=1919,y=0]

And I got 1920 1080我得到了 1920 1080

So its seems to be some problem with your screen/system.所以你的屏幕/系统似乎有问题。 Are you sure your system "knows" that you have such a screen?您确定您的系统“知道”您有这样的屏幕吗?

My windows options for "Display -> Scale and layout" are set to 125%.我的“显示 -> 比例和布局”窗口选项设置为 125%。 Thats the problem, if i set it to 100% it works like expected.这就是问题所在,如果我将其设置为 100%,它会按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM