在下面的代码中我正在初始化NSViewController
[NSResponder],带有NSWindow
, a NSOpenGLView
,呈现视图并尝试设置NSViewController
作为 Windows 第一响应者。
它不起作用。我期望能够在keyUp:
and keyDown:
方法也在下面,但什么也没有发生。
我错过了什么吗?
-(void)initwithFrame:(CGRect)frame
{
window = [[MyNSWindow alloc] initWithContentRect:frame styleMask:NSClosableWindowMask | NSTitledWindowMask backing:NSBackingStoreBuffered defer: YES ];
OpenGLView* glView = [[[OpenGLView alloc] initWithFrame:window.frame] autorelease];
window.contentView = glView;
[window makeFirstResponder:self];
[window makeKeyWindow];
[window display];
}
-(void)keyDown:(NSEvent*)theEvent
{
unichar unicodeKey = [ [ theEvent characters ] characterAtIndex:0 ];
unicodeKey = 0;
}
-(void)keyUp:(NSEvent *)theEvent
{
unichar unicodeKey = [ [ theEvent characters ] characterAtIndex:0 ];
unicodeKey = 0;
}
回到这个问题,其实问题出在别的地方。
我一直在使用这个睡眠功能来控制应用程序的帧速率:
void System::Sleep(double seconds)
{
NSDate* limit = [NSDate dateWithTimeIntervalSinceNow:seconds];
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
[runLoop runUntilDate:limit];
}
这样做似乎会完全冻结系统并阻止关键事件。
相反,使用它来安排更新功能:
[NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(updateApp:) userInfo:nil repeats:YES];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)