我们有一个游戏,如果你能从某人解锁的计算机上向安全人员发送电子邮件,你就会获得奖品。这个万圣节我设置了一个陷阱。
我有一个名为 systems-engage
的简单程序,它启动一个关键监听器并以编程方式打开我的收件箱。当有人开始使用键盘时,我希望我的程序能够以极其响亮的尖叫声发起恐怖电影图像的全屏视觉攻击。
我可以处理提到的所有其他内容,我只需要一种非常简单的方法来打开全屏窗口,该窗口只能通过我在代码中定义的转义序列关闭。
我在这里追求的是最容易实现的目标(Objective-C、C++、Java、python ruby、JavaScript hell ,无论什么都能快速而肮脏地完成工作。
我阅读了有关在 Objective-C 中打开全屏窗口的入门知识,但它可以非常轻松地关闭。这个恶作剧的目的是羞辱我的同事入侵我的计算机至少 10 或 20 秒,如果他只能按 Appl-Q,我就无法做到这一点。
万圣节快乐!
最佳答案
要在 Cocoa 应用程序中获得类似的功能,您可以将以下代码放入应用程序委托(delegate)的 - (void)applicationDidFinishLaunching:
(或类似代码)中:
// Set the key equivalent of the "Quit" menu item to something other than ⌘-Q.
// In this case, ^-⌥-⌘-Q.
// !!! Verify this and make sure you remember it or else you're screwed. !!!
NSMenu *mainMenu = [NSApplication sharedApplication].mainMenu;
NSMenu *appMenu = [[mainMenu itemAtIndex:0] submenu];
NSMenuItem *quitItem = [appMenu itemWithTitle:@"Quit <Your App Name Here>"];
quitItem.keyEquivalentModifierMask = NSEventModifierFlagControl | NSEventModifierFlagOption | NSEventModifierFlagCommand;
quitItem.keyEquivalent = @"q";
// Enable "kiosk mode" -- when fullscreen, hide the dock and menu bar, and prevent the user from switching away from the app or force-quitting.
[NSApplication sharedApplication].presentationOptions = NSApplicationPresentationHideDock
| NSApplicationPresentationHideMenuBar
| NSApplicationPresentationDisableProcessSwitching
| NSApplicationPresentationDisableForceQuit
| NSApplicationPresentationDisableSessionTermination;
// Remove the window's close button, making it no longer close with ⌘-W.
self.window.styleMask = self.window.styleMask & ~NSWindowStyleMaskClosable;
// Make the window take up the whole screen and make it full-screen.
[self.window setFrame:[[NSScreen mainScreen] frame] display:YES];
[self.window toggleFullScreen:self];
这将创建一个“信息亭”类型的应用程序,只能通过您设置的自定义退出快捷方式关闭(或者,您知道,强制关闭计算机)。演示选项可阻止用户访问菜单栏、停靠栏和应用程序切换(通过 ⌘-Tab)或空格、调出强制退出窗口或调出关机/重新启动/ sleep 窗口。基本上,请确保您设置了一个键盘快捷键来终止应用程序,否则,您将被锁定在计算机之外,除非强行关闭它。这是一个完整的 PITA。
当然,其中一些自定义也可以在 Interface Builder 中完成(在那里设置“退出”菜单项的等效键更容易,并且您也可以关闭窗口的关闭控制,如上面的评论中所述) ),但我只是想将其包含为代码,以便它更加透明(而不是上传 Xcode 项目)。
万圣节快乐! 😈
关于python - 在 OS X 上编写一个全屏不可关闭的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40313136/