0

how can i get current focused window id using objective c, the return value should be an int, help is highly appreciated! I just need to get the following line working

CGImageRef windowImage = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, winNum, kCGWindowImageBoundsIgnoreFraming);

but no matter which window that i focus at, winNum is always 0.

Chuck
  • 234,037
  • 30
  • 302
  • 389
Daniel
  • 141
  • 4
  • 7

1 Answers1

7
NSWindow *keyTarget = [[NSApplication sharedApplication] keyWindow];
NSInteger winNum = [keyTarget windowNumber];

or in one line:

[[[NSApplication sharedApplication] keyWindow] windowNumber];
Kenny Winker
  • 11,919
  • 7
  • 56
  • 78