这是我的代码:
//// delegate@interface MyDelegate : NSObject@end@implementation MyDelegate@end//// vIEw@interface MyVIEw : NSVIEw@end@implementation MyVIEw- (BOol)isOpaque { return YES;}- (BOol)canBecomekeyvIEw { return YES;}- (BOol)acceptsFirstResponder { return YES;}- (voID)keyDown:(NSEvent *)event{ printf("PRESS\n"); // it's ignoring}@end//// mainint main(int argc,const char **argv){ [NSApplication sharedApplication]; NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect( 0,100,100 ) styleMask:NSTitleDWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask backing:NSbackingStoreBuffered defer:NO]; [window setContentVIEw: [[MyVIEw alloc] init]]; [window setDelegate: [[MyDelegate alloc] init] ]; [window setAcceptsMouseMovedEvents:YES]; [window setLevel: NSfloatingWindowLevel]; [window makeKeyAndOrderFront: nil]; [NSApp run]; return 0;}解决方法 您需要使应用程序成为前台应用程序.这是主窗口接收关键事件所必需的.
ProcessSerialNumber psn = {0,kCurrentProcess};Osstatus status = transformProcesstype(&psn,kProcesstransformToForegroundApplication);总结
以上是内存溢出为你收集整理的objective-c – NSWindow不接收键盘事件全部内容,希望文章能够帮你解决objective-c – NSWindow不接收键盘事件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)