Intercepting NSMenu key events

后端 未结 2 1598
隐瞒了意图╮
隐瞒了意图╮ 2020-12-17 04:53

I am making a search field, which opens a NSMenu similar to Finder and Mail

The only problem, which drives me crazy, is that i cannot intercept the key events, once

相关标签:
2条回答
  • 2020-12-17 05:24

    KeyEquivalent is for menu shortcuts not intercepting all the keys. There is no need to intercept the NSMenu events and it is not possible to be used for that purpose. To make a suggestion box you basically need to make a custom NSWindow and make it look like a menu.

    Apple provides a Sample Code and they explained it in WWDC 2010 session 145 at some point.

    0 讨论(0)
  • 2020-12-17 05:24

    It is possible with a usage of Carbon event handlers. These functions allow interception of keyboard events while menu is open: GetEventDispatcherTarget() and InstallEventHandler(). This is a hack, but in fact, it works reliably across all MacOSX versions starting from 10.7. Here's the source code that could be used as a reference implementation: https://github.com/mikekazakov/MGKMenuWithFilter

    0 讨论(0)
提交回复
热议问题