views:

365

answers:

2

Hi Everyone:

I am making a test fullscreen application using this guide: http://www.cocoadevcentral.com/articles/000028.php. However, I am running into a problem when I want to get key input. For some reason, it seems that when you set the NSPanel to take up the screen, you also loose the ability for it to get the key down events. I tried to make a button trigger when the user types "s", which works fine in a regular panel, but doesn't seem to work when this change is applied.

Thanks for any help.

A: 

when in fullscreen mode ... the keyboard events cannot be captured.

im talking this in context with flash player's fullscreen.

donno abt other players.

Sris
A: 

It is possible to achieve. Make sure your subclassing NSPanel's (is there a reason why your not using a window?) -canBecomeKeyWindow, and both the panel and it's contentView's -acceptsFirstResponder methods to return TRUE.

Another lower level approach you could try if your designing an app that's using non standard UI (like a game), is to subclass NSApplication's -sendEvent method. Mine looks like:

  • (void)sendEvent:(NSEvent *)event { id delegate = [self delegate];

    if(([event type] != NSAppKitDefined) && [delegate shouldHandleEvents] && [delegate respondsToSelector:@selector(handleEvent:)]) [delegate handleEvent:event]; else [super sendEvent:event];
    }

Harry Jordan
Harry Jordan:I'm using NSPanel because that's what it said to do in a tutorial about fullscreen apps. :) Is it better to use a NSWindow in this case? Not sure if my app uses a standard UI, but I don't believe it does. So, in this case, would I simply have to subclass -canBecomeKeyWindow and make both of those -acceptsFirstResponder methods to return TRUE?
PF1
The main reason to use an NSPanel, over a normal window is usually for the look (thin title bar), and the way it interacts with events and other windows (i.e. floating). As it's default setting a panel doesn't become the applications key window unless it's specifically requested by a subview. If you do need to use NSPanel, you can overcome this default by setting the panels becomesKeyOnlyIfNeeded attribute to FALSE.But the short answer, is I'd recommend you use NSWindow for your example.
Harry Jordan
Harry: I am highly considering using a NSWindow after reading your response, but I don't know if it will work in this situation. In any event, thanks for your help - I now have the problem fixed.
PF1