Note that there are some explanatory texts on larger screens.

plurals
  1. POCapturing the display with cocos2d on OS X (and Kiosk mode problems)?
    text
    copied!<p>I built an app with cocos2d for the Mac and implemented <a href="http://developer.apple.com/library/mac/#technotes/tn2062/_index.html" rel="nofollow">Apple's recommended steps for a Kiosk application</a>. My goal is to have a full screen application that disallows exiting the application and captures all keyboard input.</p> <p>The problem is that, on an extended keyboard, Kiosk mode does not capture the function keys that control iTunes or the F4 Launchpad key. With process switching disabled, the user can still switch processes by pressing F4. (I filed a Radar on this, since it should be disallowed in Kiosk mode.) I tried subclassing NSApplication. I can detect the press of these keys using the following code:</p> <pre><code>- (void)mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat { switch( key ) { case NX_KEYTYPE_PLAY: if( state == 0 ) NSLog(@"Play pressed and released"); //Play pressed and released break; case NX_KEYTYPE_FAST: if( state == 0 ) NSLog(@"Next pressed and released"); //Next pressed and released break; case NX_KEYTYPE_REWIND: if( state == 0 ) NSLog(@"Previous pressed and released"); //Previous pressed and released break; case NX_KEYTYPE_LAUNCH_PANEL: if( state == 0 ) NSLog(@"Launchpad pressed and released"); //Previous pressed and released break; } } </code></pre> <p>I tried to intercept them through a custom implementation of <code>- (void)sendEvent: (NSEvent*)event</code>, but they are dispatched to the system regardless of what I do there.</p> <p>It seems that the solution to this is to "capture the display," per the <a href="https://developer.apple.com/library/mac/#documentation/graphicsimaging/Conceptual/QuartzDisplayServicesConceptual/Articles/DisplayCapture.html" rel="nofollow">Apple programming note</a>. When you capture the display, ALL keyboard input is intercepted by the application and none is dispatched further to the system. That's all well and good and I've been able to do it in a vanilla application.</p> <p>In my cocos2d OS X app, however, control of OpenGL and the GLView is handled in several of the core cocos2d files, namely, <code>CCGLView.m</code> and <code>CCDirectorMac.m</code>. I've spent hours trying to adjust those files to capture the display, but have been unable to make it work.</p> <p>For reference, this is what I'm doing (in <code>AppDelegate.m</code>) to enter Kiosk mode:</p> <pre><code>- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { ... NSApplicationPresentationOptions options = NSApplicationPresentationHideDock + NSApplicationPresentationDisableProcessSwitching + NSApplicationPresentationHideMenuBar; NSNumber *presentationOptions = [NSNumber numberWithUnsignedLong:options]; NSArray *keys = [NSArray arrayWithObjects:@"NSFullScreenModeAllScreens", @"NSFullScreenModeApplicationPresentationOptions", nil]; NSArray *values = [NSArray arrayWithObjects:[NSNumber numberWithBool:YES], presentationOptions, nil]; NSDictionary *fullScreenOptions = [[NSDictionary alloc] initWithObjects:values forKeys:keys]; [glView_ enterFullScreenMode:[NSScreen mainScreen] withOptions:fullScreenOptions]; [director runWithScene:[MyLayer scene]]; } </code></pre> <p>How can I capture the display (note: this is not the same as taking a screenshot!) <strong><em>in cocos2d</em></strong> and prevent the function keys from speaking to anything other than my application?</p> <hr> <p><strong>Additional info:</strong> <code>-enterFullScreenMode:withOptions:</code> does capture the display, but only if you do not send in <code>NSFullScreenModeApplicationPresentationOptions</code> as one of the options. The Apple docs specify this in the NSView and Kiosk mode documentation:</p> <blockquote> <p>When the options dictionary you pass to <code>enterFullScreenMode:withOptions:</code> does contain a value for <code>NSFullScreenModeApplicationPresentationOptions</code>, AppKit does not capture any displays, because doing so would prevent the showing of presentationOptions-controlled UI elements such as the menu bar and Dock.</p> </blockquote> <p>Nevertheless, the media/iTunes/volume function keys are not intercepted when you capture the display, which is part of the problem I was trying to answer when I wrote this question. I filed a Tech Support question with Apple because it appears not to be possible to disable them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload