1

我读过可可关键事件处理文档。并获得如下代码片段示例:问题是当我更改除英语以外的输入法(如中文)时。代码片段不起作用,它仍然返回单个字母字符,但不是 unicode 中文字符。有什么建议还是我遗漏了部分文件?

- (void)keyDown:(NSEvent *)theEvent
{
    [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
}

// The following action methods are declared in NSResponder.h
- (void)insertTab:(id)sender
{
    if ([[self window] firstResponder] == self)
    {
        [[self window] selectNextKeyView:self];
    }
}


- (void)insertBacktab:(id)sender
{
    if ([[self window] firstResponder] == self)
    {
        [[self window] selectPreviousKeyView:self];
    }
}

- (void)insertText:(id)string
{
    [super insertText:string];  // have superclass insert it
}
4

2 回答 2

0

如果默认实现([NSEvent characters]??charactersIgnoringModifiers)不起作用,您可以尝试通过事件的 访问该值@property CGEvent,然后查看是否使用类似CGEventKeyboardGetUnicodeString.

于 2012-08-20T07:43:05.870 回答
0

如果您正在捕获文本NSTextView(我猜您是,因为您有-insertText:),那么您可以使用NSTextViewDelegate捕获 Unicode 输入。

例如,实施[NSTextViewDelegate textView:shouldChangeTextInRange:replacementString:].

NSEvent在击键级别操作的 不同,此方法在更高级别的 Unicode 字符上操作。

于 2014-03-21T18:09:23.210 回答