单击后显示鼠标位置(objective-c)

时间:2014-09-27 22:53:33

标签: objective-c position mouse

我搜索如何创建一个在点击后显示光标位置的应用程序。我找到了如何报告当前鼠标位置,但我不知道如何在我的窗口中显示tis!

我想只需点击一个位置并在Windows标签上显示此位置

关于Xcode文档我发现- (void)mouseUp:(NSEvent *)theEvent但我不知道如何使用它!

1 个答案:

答案 0 :(得分:1)

Subclass your NSWindow and then override the mouseDown Event Method

- (void)mouseDown:(NSEvent *)theEvent
{
    //get the point position where the mouse was clicked on the NSWindow !
    NSPoint event_location = [theEvent locationInWindow];
    NSLog(@"Clicked %f %f",event_location.x,event_location.y);
    // use event_location.x and event.location.y to show the position whereever you like
}