Java Awt 鼠标位置坐标计算

huangapple 未分类评论58阅读模式
英文:

Java Awt mouse position coordinates calculation

问题

我可以通过以下代码获取光标的位置,但我不理解坐标是如何计算的。

MouseInfo.getPointerInfo().getLocation();

如果鼠标位于右上角,坐标为"java.awt.Point[x=2047,y=0]",但我的屏幕分辨率是2560 x 1440,所以我预期坐标应为[x=2560,y=0]。

那么这些坐标是如何计算的呢?

英文:

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].

So how are these coordinated calculated?

答案1

得分: 0

当我尝试这样做:

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

它输出:

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

而我的屏幕分辨率是 1920x1080。所以似乎存在屏幕或系统的某些问题。你确定你的系统“知道”你有这样的屏幕吗?

英文:

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

So its seems to be some problem with your screen/system. Are you sure your system "knows" that you have such a screen?

答案2

得分: 0

我的Windows选项用于“显示 -> 缩放和布局”设置为125%。
问题就在这里,如果我将其设置为100%,它会按预期工作。

英文:

My windows options for "Display -> Scale and layout" are set to 125%.
Thats the problem, if i set it to 100% it works like expected.

huangapple
  • 本文由 发表于 2020年3月15日 18:22:23
  • 转载请务必保留本文链接:https://java.coder-hub.com/60691868.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定