0

I am making an application that requires me to make an NSButton that can simulate a keyboard shortcut. I need to know how to assign an NSButton to a macOS keyboard shortcut command. I am wanting to create a small application that would enable me to toggle on Target Display Mode (Command + F2) without the use of a keyboard. How can I simulate using the keyboard shortcut (Command + F2) to the button when it is pressed so that it could turn on Target Display Mode. I appreciate all responses.

Adam H
  • 109
  • 12
  • Take a good look at the properties of the button. – El Tomato Aug 22 '17 at 01:05
  • What are you trying to accomplish? The user can activate Spotlight themselves -- your application should typically not be activating it for them. –  Aug 22 '17 at 02:15
  • @duskwuff: I am aware that the user is capable of activating Spotlight themselves. (An application that does that for them would indeed be pointless.) I was just using that as an example. Didn't intend to complicate things. I was just going to create a small menu bar app for myself that would enable me to toggle on Target Mode Display without the use of a keyboard (thus the point of the button). I'll update the question if you found it confusing. – Adam H Aug 22 '17 at 02:32
  • Isn't there already a menu bar item for that? "Show mirroring options in the menu bar when available" in the Displays preference pane. –  Aug 22 '17 at 03:00
  • @duskwuff No, that is for AirPlay, not Target Display Mode. – Adam H Aug 22 '17 at 05:27
  • @Willeke Thanks, I wasn't aware that this question was asked before. I was needing the answer in Swift, which was also answered [here](https://stackoverflow.com/questions/27484330/simulate-keypress-using-swift?noredirect=1&lq=1). Thanks. – Adam H Aug 22 '17 at 16:07

0 Answers0