NSOpenGLView 子类中带有键盘事件的烦人的碰撞声
我已经重写了 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;
}
}
I've overridden an NSOpenGLView to handle keyboard events. The event detection is working fine, but every time I press a key I hear and annoying bump sound. How can I tell my view to chill out?
Here's what my keyUp: method looks like:
-(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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有您的代码,很难说,但我猜您将事件传递给了 super,即使您“消耗”了它。蜂鸣声表示“没有人正在处理此事件,因此不允许键盘输入。”如果您使用(处理)该事件,请勿将其传递给 super ,否则系统将假设您的视图未处理该事件。
Hard to tell without your code but I'd guess you passed the event up to super even though you "consumed" it. The beep tone is saying "nobody is handling this event so keyboard input isn't allowed." If you consume (handle) the event, don't pass it to super or the system will assume your view didn't handle the event.