Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

objective c - Missing keyUp events on meaningful key combinations (e.g. "Select till beginning of line")

I have an NSTextField which uses as an extended NSTextFieldCell, which creates a custom field editor, that intercepts and records key events. (Knowing the key events is important for the application, but the text field is still supposed to work as usual, by calling the [super ...] method). This is what the official documentation suggests for this problem.

I do receive most keyUp events while typing, but in certain cases I don't get one. It seems to happen, when pressing a key combination that has an action attached to it. E.g. Cmd-Shift-Left is not issuing an keyUp event. That input makes the whole line from point to the beginning appear selected, but already when the keyDown is received.

In those cases where it is missing, when looking at -performKeyEquivalent: by overriding it, I see this is called. Why is the keyUp not delivered?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For others, this is the code to "fix" it:

- (void)sendEvent:(NSEvent *)event {
    if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
        [[self keyWindow] sendEvent:event];
    else
        [super sendEvent:event];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...