Cocoa Key Event Question

Don’t worry, this doesn’t have to do with games :stuck_out_tongue: (I will be getting a Unity license pretty soon). I’m wondering how to get a Cocoa (Fullscreen, if it should matter) app to capture keypresses so that when a user hits F8 the window appears (I have the code for checking what the keypress is, and handling it, all I need is watching it). Should I subclass something?

Perhaps I should provide a bit more info:
I’m working on a web browser that acts a bit like dashboard. I’m having trouble with the key commands.

  • In Controller.h and Controller.m I define the main window and the web panel
  • In MyWindow.m and h I subclass NSWindow so that it can become the key window (fullscreen).
  • If I put my code in MyWindow.m it doesn’t work because mainwindow belongs to Controller and importing it won’t work (I’m pretty sure I wouldn’t instantiate it either).
  • If I put it in Controller it doesn’t work because controller is, well; a controller.

Any help would be appreciated!

(PS I’m just learning Cocoa so I’m sure something I said will have not made sense or have been “the wrong way to do it”)

You might want to check out iDevApps and/or iDevGames for non-Unity related Mac programming help. :slight_smile:

I’m not a Cocoa programmer so I can’t really help, unfortunately…

I checked those, however I just found a solution (Google; actually, it is on iDevGames!)..

Hmm.. I think thats a fix to using cmd + any key. But I think you can use ordinary key's without subclassing NSApplication... I might be wrong though (im learning too)

- (void) keyDown:(NSEvent *)theEvent
   unichar unicodeKey;
   unicodeKey = [ [ theEvent characters ] characterAtIndex:0 ];
   switch( unicodeKey )
            case 'f':
                //do something!

            case NSUpArrowFunctionKey:
                //move something       

no wait a minute, it's Best just to subclass NSApp, my bad!