检测 Ctrl + Return 或 Ctrl +输入按键
我发现很难找到关于此事的任何官方信息。
我有一个 TextView 并覆盖 keyDown 事件,并尝试检测用户是否按下 Ctrl + Enter。
- (void)keyDown:(NSEvent *)theEvent
{
if([theEvent modifierFlags] & NSControlKeyMask && /* how to check if enter is pressed??? */)
{
NSLog(@"keyDown: ctrl+enter");
if(_delegate)
{
if([_delegate respondsToSelector:@selector(didSomething:)])
{
[_delegate performSelector:@selector(didSomething:) withObject:nil];
}
}
}else
{
[super keyDown:theEvent];
}
}
我尝试过不同的方法,但没有任何效果。
有人吗?
(我很抱歉问这么一个微不足道的问题,但我已经用谷歌搜索了一段时间,但没有找到任何东西)
I find it very hard to find anything official on this matter.
I have a TextView and override the keyDown event and try to detect if the user pressed Ctrl + Enter.
- (void)keyDown:(NSEvent *)theEvent
{
if([theEvent modifierFlags] & NSControlKeyMask && /* how to check if enter is pressed??? */)
{
NSLog(@"keyDown: ctrl+enter");
if(_delegate)
{
if([_delegate respondsToSelector:@selector(didSomething:)])
{
[_delegate performSelector:@selector(didSomething:) withObject:nil];
}
}
}else
{
[super keyDown:theEvent];
}
}
I have tried different things but nothing worked.
anyone?
(i'm sorry to ask such a trivial question but i have googled for a while now and haven't found anything)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者,您可以使用委托的
textView:doCommandBySelector:
:Alternatively, you can use the delegate's
textView:doCommandBySelector:
:您可以覆盖 键盘操作(插入换行符),当 ctrl-return 时发送在文本视图中输入:
Instead of overriding
-keyDown:
, you could override the keyboard action (insert a line break) that’s sent when ctrl-return is typed in a text view: