gpt4 book ai didi

objective-c - 在 Mac 应用程序中拦截 Command-Quit?

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

我想为 Mac (Mavericks) 制作一个不处理命令退出选项的应用程序。

我找到了以下解决方案,但它一定已经过时了,因为我收到错误:

    CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap,
kCGHeadInsertEventTap,
kCGEventTapOptionDefault,
CGEventMaskBit(kCGEventKeyDown),
&KeyDownCallback,
NULL);

CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CFRelease(runLoopSource);
CGEventTapEnable(eventTap, true);

还有其他方法吗?谢谢。

最佳答案

只需让您的应用程序委托(delegate)实现 applicationShouldTerminate:方法:

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
// work out whether to actually quit or not
BOOL shouldQuit = /* insert logic here */;
if (shouldQuit)
return NSTerminateNow;
else
return NSTerminateCancel;
}

关于objective-c - 在 Mac 应用程序中拦截 Command-Quit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24377811/

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