我已经重写了 NSOpenGLView 来处理键盘事件。事件检测工作正常,但每次我按下一个键时,我都会听到恼人的碰撞声。我怎样才能让我的观点冷静下来?
这是我的 keyUp: 方法的样子:
-(void) keyUp:(NSEvent *)theEvent
{
NSString *characters = [theEvent charactersIgnoringModifiers];
if ( [characters length] != 1 )
return;
unichar keyChar = [characters characterAtIndex:0];
if ( keyChar == NSLeftArrowFunctionKey )
{
//do something
return;
}
if ( keyChar == NSRightArrowFunctionKey )
{
//do something
return;
}
if ( keyChar == NSUpArrowFunctionKey )
{
//do something
return;
}
if ( keyChar == NSDownArrowFunctionKey )
{
//do something
return;
}
}