views:

39

answers:

1

In Cocoa/ Objective C I need to be able to programmatically find out which app or process has the keyboard focus. This may be done by doing a 'hit-test', but I'm not exactly sure.

I also need to get the process ID number and Window Title of app that has the keyboard focus.

Objective C or C only please!

Snippets appreciated!

+1  A: 

You can use [NSWorkspace sharedWorkspace] activeApplication to find the front application. The Accessibilty API can be used to look inside the application to get window titles etc.

Another option is to use the Quartz Window Services function CGWindowListCopyWindowInfo() to get a list of all windows

David Gelhar