我正在为 Unity3D 创建 Mac OS 插件(捆绑包)。如何拦截输入 cmd-f 组合(切换全屏模式)?我不能创建自己的窗口,我只能使用默认(mainWindow)。我尝试使用 NSNotificationCenter,但我需要停止事件,我不需要通知。我尝试创建 NSResponder 并将其添加到捕获输入事件,但有些东西不起作用。任何想法如何做到这一点?
NSWindow* window = [[NSApplication sharedApplication] mainWindow];
NSView* view = [window contentView];
NSResponder* oldresp = [view nextResponder];
MyResponder* myres = [MyResponder alloc];
[myres retain];
[view setNextResponder:myres];
和
@interface MyResponder : NSResponder
{
}
- (void)keyDown:(NSEvent *)theEvent;
@end
@implementation MyResponder
- (void)keyDown:(NSEvent *)theEvent
{
NSLog(@"%@",@"!KeyDown Event");
NSString *theArrow = [theEvent charactersIgnoringModifiers];
unichar keyChar = 0;
if ( [theArrow length] == 1 )
{
keyChar = [theArrow characterAtIndex:0];
if ( keyChar == NSModeSwitchFunctionKey )
{
NSLog(@"%@",@"!!!___!!! GOT NSModeSwitchFunctionKey !!!");
return;
}
NSLog(@"%@ %d",@"! Key:",keyChar);
}
[super keyDown:theEvent];
}
@end