"Easter Egg" style key combination changes

  • I would like to include a special debug menu in one of my application.
    I do not want this menu easily available, as it might give the average
    end user the ability to do things that would cause support nightmares
    for the application. What I want is to have the menu appear when they
    hold certain keys and click the Application menu, and vanish when they
    let the keys go... I'm having trouble finding information on this and
    honestly I do not even know where to start looking. Any ideas?
  • On Jan 20, 2008, at 12:21 PM, Development wrote:

    > I would like to include a special debug menu in one of my
    > application. I do not want this menu easily available, as it might
    > give the average end user the ability to do things that would cause
    > support nightmares for the application. What I want is to have the
    > menu appear when they hold certain keys and click the Application
    > menu, and vanish when they let the keys go... I'm having trouble
    > finding information on this and honestly I do not even know where to
    > start looking. Any ideas?

    While this may be possible, it would probably be better for you to
    implement what Safari does.  Basically, come up with a "debug" key and
    if that's there in your app's user defaults, then just add in the menu
    near app startup (e.g. in awakeFromNib).

    You can instruct your users to enable debug mode by doing this from
    Terminal:

    defaults write com.yourcompany.yourapp IncludeDebugMenu 1

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • My experiment and it's results:
    Lets pretend you want a hidden menu only available when certain keys
    are held down. Further more you do not want some one to just open the
    nib and see that the menu actually exists some where... I have a
    similar issue and after mailing the list and playing with it found one
    way to accomplish this. Below is the code which will build the hidden
    menu programatically and the nib selections I used.

      NSMenuItem * altAbout = [[NSMenuItem alloc]initWithTitle:@"Alternate
    About Menu" action:@selector(openAbout:) keyEquivalent:@"!"]; //The
    @"!" key equiv seems to negate any kind of equivalent but will allow a
    key press change. I suspect every one but me knew this.
      [altAbout setTag:242]; //Any number other than the original menu
    item's number will do
      [altAbout setKeyEquivalentModifierMask:(NSShiftKeyMask |
    NSAlternateKeyMask | NSCommandKeyMask | NSControlKeyMask)]; //just
    include the modifier(s) you want
      [altAbout setTarget:self];
      [altAbout setAlternate:YES];
      [[appMenu submenu]insertItem:altAbout atIndex:1]; // appMenu is
    defined in the header and linked in the nib. You want to insert this
    new item just below whatever index the item it is an alt for resides
    for of course, obvious reasons.

    Now In the NIB I did the following:

    First, I connected the 'appMenu' NSMenuItem I declared in the Header
    to the actual application menu, this step is of course obvious. Next,
    I selected the About <Application Name> Menu Item and checked the
    Alternate option(A step I am sure would either cause problems for an
    item several indexes down the list, or in this case is completely
    meaningless since the option only refers to being an alt to it's
    predecessor.) Next For the Key equiv I held shift, apple, 1 (Which of
    course made the Equiv command-!) and as near as I can tell it NULLs
    the equiv but leaves a modifier in place. You will also want to make
    sure that both the alternate and original menu items point to the same
    selector. In the selector you can use the [sender tag] to figure out
    which sent the message. I say this because when I had them pointed to
    different selectors it crashed the application when I selected the
    alt, then released the keys and tried to open the application menu. I
    am sure this would be the obvious result to every one but me though.
    Then build the app, launch, click the App menu and see the original,
    then hold the modifiers you've designated and whala it changes.

    Now, as I look at the code I am fairly sure it is easier to do this
    than what I've outlined but meh, it works so it'll get you started. In
    other words I suspect that setting the key equiv to null or @"" or
    something, then setting the modifier mask would have the same effect
    but I didn't try it and since this works I probably won't.

    Forgive the N00b explanation, but I have always found that more
    information or explanation than I needed is better than not enough.
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today