当我使用这段代码时,我的 Y 鼠标位置值有误。返回值为(x, y+20)。
int Height = int [[Window contentView] frame].size.height;
int x = (int)[(NSEvent *)event locationInWindow].x;
int y = Height - (int)[(NSEvent *)event locationInWindow].y;
我认为Height是窗口的高度:`title bar + rect client.我想要 Height 的真实值;
最佳答案
您可以将坐标转换为 View 。
- (void)mouseMoved:(NSEvent *)event
{
NSPoint locationInView = [self convertPoint:[event locationInWindow]
fromView:yourView];
}
确保获得某种事件(在我的示例中是鼠标事件)。确保它们已启用。
[window setAcceptsMouseMovedEvents:YES];
关于c++ - 如何在 Mac OSX 上的窗口客户端中获得真实的鼠标位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43260579/