gpt4 book ai didi

Java - 如何检测某些多显示器设置的垂直位移?

转载 作者:行者123 更新时间:2023-11-30 07:04:50 25 4
gpt4 key购买 nike

在许多具有不同支架高度的多显示器设置中,可以在软件中调整显示器的垂直位置,以便它们的图形正确对齐。将垂直位移添加到 Windows 鼠标坐标以实现此效果;图中紫色所示: enter image description here我正在构建一个程序,需要知道用户的鼠标何时到达任何监视器的顶部。我尝试使用 MouseInfo.getPointerInfo().getLocation().y==0,但是当监视器在软件中移位时,这将不起作用,因为监视器的顶部可能并不总是为零。

是否有可靠且有效的方法来识别多个显示器之间的偏移?

最佳答案

感谢@Siguza 的评论,我能够完成我想要完成的任务。简单来说,你可以找到Rectangle使用以下代码获取鼠标所在监视器的对象: MouseInfo.getPointerInfo().getDevice().getDefaultConfiguration().getBounds()

还可以使用 Windows 中显示器的数字索引找到每个显示器的矩形。代码 GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDefaultConfiguration().getBounds() 将返回主显示器的 Rectangle(索引 0),其他可以通过更改 GraphicsDevice 的索引来访问监视器

显示器的垂直位移位于Rectangle对象的.y属性中;该值可用于识别监视器的最顶层坐标。

@Siguza 的评论:

Haven't tested it, but according to the docs, GraphicsConfiguration.getBounds() sounds like what you're looking for. You should be able to get all monitors with GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenD‌​evices(), and their configurations with .getConfigurations(), but I idk how to choose from that array.

关于Java - 如何检测某些多显示器设置的垂直位移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40322941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com