// Pointer info
PointerInfo pi = MouseInfo.getPointerInfo();
Point mp = pi.getLocation();
// The devices bounds
Rectangle bounds = getDeviceBounds(pi.getDevice());
// Create new "virtual" point based on the mouse point
virtualPoint = new Point(mp);
// Subtract the x/y position of the device
virtualPoint.x -= bounds.x;
virtualPoint.y -= bounds.y;
// Clip negative values...
if (virtualPoint.x < 0) {
virtualPoint.x *= -1;
}
if (virtualPoint.y < 0) {
virtualPoint.y *= -1;
}
1 回答
基本上,我所做的是取
PointerInfo
并从中减去GraphicsDevice
界限,如果结果少于0
(因为屏幕是主屏幕左侧),我将结果乘以-1
解决方案的核心看起来像这样......
以下示例显示第一行的实际桌面鼠标位置(由
MouseInfo
报告),第二行显示GraphicsDevice
上下文中的"screen"位置