编辑 NSTextField 时添加热键

发布于 2024-10-02 15:22:07 字数 274 浏览 2 评论 0原文

是否可以仅在编辑某个 NSTextField 时添加热键?例如,当您在此文本字段中时,我希望您按 Command + 1 插入一个字符串,按 Command + 2 插入另一个文本字符串等,但仅当您编辑该 NSText 字段时。

我尝试将 keyDown 方法添加到我的子类 NSTextField 中,但这似乎从未被触发。如果我将其更改为 keyUp,它将被触发,但如果按住命令键则不会。

似乎当我搜索热键时,我找到的唯一信息是全局热键(即使应用程序不可见时也会激活的热键),这不是我正在寻找的信息。

Is it possible to add hotkeys only when you're editing a certain NSTextField? For example, when you're in this text field I would like it if you pressed Command + 1 it inserted one string, and Command + 2 to insert another text string, etc, but only when you're editing that NSText field.

I tried adding a keyDown method to my subclassed NSTextField, but that didn't seem to ever get fired. If I changed it to keyUp it gets fired, but not if the command key is held down.

It seems when I'm searching for hotkeys the only information I find is on global hotkeys (ones that activate even when the app isn't visible) which isn't what I'm looking for.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

单调的奢华 2024-10-09 15:22:07

如果您有一个带有该键盘快捷键的菜单项,则可以实现 validateUserInterfaceItem: 以在您的字段位于响应程序链中时启用它。我不确定这是否适用于隐藏的菜单项。

If you had a menu item with that keyboard shortcut, you could implement validateUserInterfaceItem: to enable it when your field is in the responder chain. What I'm not sure about is whether that would work for a hidden menu item.

攀登最高峰 2024-10-09 15:22:07

NSTextField 不处理 keyDown: 本身。相反,他们似乎依赖于称为“字段编辑器”的中介(从此处的类似问题中找到此信息 http://www.cocoabuilder.com/archive/cocoa/51299-custom-nstextfield-keydown.html)。

苹果有一些关于这个主题的更多信息 - http ://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextEditing/Tasks/FieldEditor.html

NSTextField's to not deal with keyDown: themselves. They instead seem to rely on intermediaries called Field Editors (found this info from a similar question here http://www.cocoabuilder.com/archive/cocoa/51299-custom-nstextfield-keydown.html).

Apple has some more info on the subject - http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextEditing/Tasks/FieldEditor.html

游魂 2024-10-09 15:22:07

当我的文本字段是第一响应者时,我最终对窗口进行了子类化并覆盖了 sendEvent 。

I ended up subclassing my window and overriding sendEvent when my text field is the first responder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文