Mac 용 코드를 배우려고합니다. 나는 잠시 동안 자바 녀석이었습니다. 그래서 나는 내가 겪고있는 문제가 코코아에 대한 간단한 오해라고 생각합니다.addGlobalMonitorForEventsMatchingMask 만 마우스 위치를 반환합니다.
-(IBAction)beginEventMonitor:(id)sender {
_eventMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseUpMask)
handler:^(NSEvent *incomingEvent) {
//NSWindow *targetWindowForEvent = [incomingEvent window];
NSLog(@"Got a mouse click event at %@", NSStringFromPoint([incomingEvent locationInWindow]));
}];
}
-(IBAction)stopEventMonitor:(id)sender {
if (_eventMonitor) {
[NSEvent removeMonitor:_eventMonitor];
_eventMonitor = nil;
}
}
이 마우스 클릭은 글로벌 수준에서 일어날 때 말해 간단한 훅은 다음과 같습니다
나는 다음과 같은 코드를 가지고있다. 처리기가 작동하지만 incomingEvent의 내용이 아무것도 설정되지 않은 것처럼 보입니다. 내가 찾을 수있는 유일한 유용한 정보는 클릭 한 순간의 마우스 위치와 클릭 한 창의 windowId입니다.
더 자세한 정보를 얻을 수 없습니까? 모니터를 올바르게 설치하지 않습니까? 나는 어떤 창을 클릭했는지 알 수 있기를 정말로 원하지만, 마우스 위치 나 windowId를 유용하게 사용할 수있는 방법을 찾을 수조차 없다.
은 마우스 이벤트와 함께 훌륭하게 작동합니다. keyDown 이벤트에 대해 알고 있습니까? –