0

I'm trying to listen to all mouse clicks that the user makes. I need to know which window the user has clicked on (presumably by its CGWindowID). I am listening to all clicks through a CGEventTap, but now I can't find out how to get the window that was clicked. Do you know of some way to retrieve the window id from the CGEventRef object?

Plus, I know that I can get the window id, when using [NSEvent addGlobalMonitorForEventsMatchingMask] by getting [event windowNumber], but I can't use this listener, because for some reason, after the listener is set up it blocks all inputs to my own window. Maybe someone also knows, where this is coming from?

Thanks!

Pedro

user1118321
  • 25,567
  • 4
  • 55
  • 86
torpedro
  • 494
  • 5
  • 13
  • I don't think `addGlobalMonitorForEventsMatchingMask:handler:` blocks inputs to your own window, it just doesn't listen to them, as the documentation says. – JWWalker Feb 16 '15 at 22:47

1 Answers1

0

Are you able to access the windowNumber after converting the CGEvent into an NSEvent?

CGEvent cgEvent = EVENT_FROM_YOUR_CGEVENT_TAP;
NSEvent *nsEvent = [NSEvent eventWithCGEvent:cgEvent];

NSInteger windowNumber = [nsEvent windowNumber];
pkamb
  • 33,281
  • 23
  • 160
  • 191