views:

77

answers:

1

Hi All,

I'm writing a plugin for an application. I cannot derive from NSApplication as it is a third party application. I can get the callback in my plugin when any key is pressed. But I will not know what key is pressed. So is there any call in Cocoa to find the last key pressed when I get the callback? I only have NSView object.

Any ideas will help me a lot.

Thanks,

Dheeraj.

+2  A: 

A couple of thoughts:

  1. Use [NSApp currentEvent]. I know you don't think you have an NSApplication instance, but you should try this. It might work.
  2. Do some event monitoring in your plugin (CGEventTap, NSEvent local monitor, etc) and record whenever you see a keypress event.
Dave DeLong
Thanks for your thoughts Dave DeLong. I have tried CGEventTap but that needs the user to check the Enable access for assistive devices flag in System Preferences.I will try [NSApp currentEvent] and let you know.
Dheeraj
Thanks Dave DeLong. [NSApp currentEvent] works fine.
Dheeraj