Re: Toddler-proofing an app (disabling spotlight keyboard shortcut)?
Re: Toddler-proofing an app (disabling spotlight keyboard shortcut)?
- Subject: Re: Toddler-proofing an app (disabling spotlight keyboard shortcut)?
- From: Ken Thomases <email@hidden>
- Date: Sat, 22 Sep 2012 01:59:59 -0500
On Sep 21, 2012, at 9:39 AM, Clay Heaton wrote:
> My 20 month old daughter loves to bang on the keys of the keyboard. I made
> a simple cocos2d app that shows random animal pictures (with noises) when
> she presses keys. (This has proved very popular with her and she now can
> identify all of the animals!)
>
> Anyhow, she'll sit on my lap and bang the keyboard for 4-5 minutes at a
> time. The problem is that she very often hits command-space and then other
> keys, causing the app to exit full screen and Spotlight to activate. From
> time to time, she does other things, such as hiding the dock (in the
> background), switching spaces, etc.
>
> Is there a way for me to disable some of these system-level keyboard
> commands when the app that I made has focus? I came across some old
> Carbon, namely:
>
> void *oldHotKeyMode = PushSymbolicHotKeyMode(kHIHotKeyModeAllDisabled);
> ...
> PopSymbolicHotKeyMode(oldHotKeyMode);
>
> but I run into compiler errors when I try to use these:
>
> ld: symbol(s) not found for architecture x86_64
>
> I'm using Xcode 4.5 and would like to continue using ARC if possible (since
> GC is depreciated).
>
> Any ideas?
If your app is full-screen, you might capture the display. See the Quartz Display Services <https://developer.apple.com/library/mac/#documentation/graphicsimaging/Conceptual/QuartzDisplayServicesConceptual/Articles/DisplayCapture.html>. Capturing the display prevents Command-Tab app switching, Exposé/Mission Control, Spotlight, etc. I believe it will also prevent system keyboard shortcuts (e.g. hiding the Dock with Command-Option-D) from reaching the wider system.
It might also work to set the application presentation options. -[NSApplication setPresentationOptions:] with options including NSApplicationPresentationDisableAppleMenu and NSApplicationPresentationDisableProcessSwitching. Or those options can be included with the options passed to -[NSView enterFullScreenMode:withOptions:] under the NSFullScreenModeApplicationPresentationOptions key.
Finally, you can use a custom subclass of NSApplication, override -sendEvent:, detect events which correspond to hot keys, and don't pass them through to super. Detecting hot keys is kind of hard. There's CopySymbolicHotKeys(), but it can be hard to interpret the output data and it's probably also not available in 64-bit. For a private-use-only app, you can get away with hard-coding keys that actually cause you trouble.
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden