2 Replies
      Latest reply: Feb 5, 2017 4:22 PM by Claude31 RSS
      Claude31 Level 4 Level 4 (815 points)

        How can I detect that option key is pressed when a menu is selected, to:

        - change menu title

        - perform a specific action

        Apple doc on this is really below minimum (useless):

        Managing Alternates
             var isAlternate: Bool
             A Boolean value that marks the menu item as an alternate to the previous menu item.
        

         

        More generally, I would like to set a global value each time the altrenate key is pressed in my app.

        • Re: Detect option key is pressed when menu selected
          eskimo Apple Staff Apple Staff (5,995 points)

          How can I detect that option key is pressed when a menu is selected, to:

          That’s not how you generally do things.  Rather, you create multiple menu items next to each other in the menu bar, with all but the first having the isAlternate set.  The system then merges them together and only shows the one that matches the current modifiers.  And because they are separate menu items, they can have separate actions.

          To see this in action:

          1. Create a new project from the Cocoa Application template

          2. In the main menu, select Paste and Match Style and check Alternate in the Attributes inspector

          3. Run the app

          4. When you bring down the edit menu, you’ll just see Paste

          5. If you press command-shift, it’ll change to Paste and Match Style

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"