开发者

How to implement key equivalent for NSSearchField

开发者 https://www.devze.com 2022-12-16 03:30 出处:网络
I have a Cocoa application I am building which contains an NSSearchField control. I want to enable a keyboard shortcut / key equivalent so when the uses presses COMMAND-OPTION-F, the search field gets

I have a Cocoa application I am building which contains an NSSearchField control. I want to enable a keyboard shortcut / key equivalent so when the uses presses COMMAND-OPTION-F, the search field gets focus.

However, after much searching, it is not clear to me what the best way to implement this is. There is not an option to set this for the NSSearchField in Interface Builder.

开发者_如何学编程

Is the solution to subclass NSSearchField and listen for the keyDown event (and then see if the key equivalent is pressed?)


You can always add a menu item with a key equivalent of F i.e. CommandOptionF. In the menu's action, just manually make the search field the first responder using

[window makeFirstResponder:searchField]; 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号