gpt4 book ai didi

cocoa - 对于某些击键,performKeyEquivalent 被调用两次

转载 作者:行者123 更新时间:2023-12-03 17:12:24 24 4
gpt4 key购买 nike

按“Command +”会导致两次 -performKeyEquivalent 调用。这是第一次调用的堆栈跟踪片段:

1   AppKit                              0x00007fff903da2f9 -[NSView _performKeyEquivalent:conditionally:] + 41
2 AppKit 0x00007fff903da442 -[NSView performKeyEquivalent:] + 166
3 AppKit 0x00007fff903da2f9 -[NSView _performKeyEquivalent:conditionally:] + 41
4 AppKit 0x00007fff903da259 -[NSWindow performKeyEquivalent:] + 64
5 AppKit 0x00007fff903da044 -[NSApplication _handleKeyEquivalent:] + 462
6 AppKit 0x00007fff90297173 -[NSApplication sendEvent:] + 4480

第二次调用:

1   AppKit                              0x00007fff903da2f9 -[NSView _performKeyEquivalent:conditionally:] + 41
2 AppKit 0x00007fff903da442 -[NSView performKeyEquivalent:] + 166
3 AppKit 0x00007fff903da2f9 -[NSView _performKeyEquivalent:conditionally:] + 41
4 AppKit 0x00007fff903da259 -[NSWindow performKeyEquivalent:] + 64
5 AppKit 0x00007fff903da044 -[NSApplication _handleKeyEquivalent:] + 462
6 AppKit 0x00007fff900e3927 -[NSApplication _handleSpecialAlternateKeyEquivalent:] + 656
7 AppKit 0x00007fff9029718e -[NSApplication sendEvent:] + 4507

如您所见,第二个 -performKeyEquivalent 调用是由 -[NSApplication _handleSpecialAlternateKeyEquivalent:] 发起的。那么,谁能告诉我“Command +”击键有什么特别之处,以至于它不需要一次而是两次 -performKeyEquivalent 调用,以及如何过滤掉第二个调用?

最佳答案

最可能的原因是第一次调用返回NO,因此 AppKit 使用略有不同的事件再次尝试。您是否覆盖performKeyEquivalent:?您第一次返回NO吗?

<小时/>

来自Cocoa Event Handling Guide: Handling Key Events的笔记:

NSWindow subclasses are discouraged from overriding performKeyEquivalent:.

Note: Beginning with OS X v10.5, if a key equivalent is not recognized, NSWindow sends it as an NSKeyDown event to the first responder. This behavior enables custom key-binding entries with Command-key modifiers. In addition, NSApplication sends a Control-key event to the key window via performKeyEquivalent: before sending it as an NSKeyDown event through the responder chain. This behavior allows more reliable use of Control-key events as menu key equivalents.

关于cocoa - 对于某些击键,performKeyEquivalent 被调用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18404230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com