I can't make a key equivalent work on an NSButton that I have created programatically. Can anyone advise me of what I'm doing wrong? The button works as intended when pressed, but the key equivalent will not work.
NSButton *ESCButton = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 10, 10)];
[[quickEntryWindow contentView] addSubview:ESCButton];
[[ESCButton cell] setKeyEquivalent:@"\E"];
[ESCButton setTarget:self];
//[ESCButton setTransparent:YES];
[ESCButton setAction:@selector(hideQuickEntryWindow)];开发者_如何学Go
[quickEntryWindow setDefaultButtonCell:[ESCButton cell]];
[quickEntryWindow enableKeyEquivalentForDefaultButtonCell];
-setDefaultButtonCell:
turns the cell into the window default button cell, which necessarily has key equivalent \r
(Return/Enter). If you want to use another key equivalent, remove
[quickEntryWindow setDefaultButtonCell:[ESCButton cell]];
[quickEntryWindow enableKeyEquivalentForDefaultButtonCell];
精彩评论