简体   繁体   English

在 OS X 上编写一个全屏不可关闭的窗口

[英]Program a full screen uncloseable window on OS X

We have a game at work where if you can send the security guy an email from someone's unlocked computer you get a prize.我们有一个游戏正在运行,如果您可以从某人的未锁定计算机向安全人员发送电子邮件,您将获得奖励。 This Halloween I am setting a trap.这个万圣节我设下陷阱。

I have a simple program called systems-engage that starts a key listener and opens my inbox programmatically.我有一个名为systems-engage的简单程序,它启动一个关键侦听器并以编程方式打开我的收件箱。 When someone starts using the keyboard I want my program to launch a full-screen visual assault of horror film images with extremely loud screaming.当有人开始使用键盘时,我希望我的程序以极其响亮的尖叫声对恐怖电影图像进行全屏视觉攻击。

I can handle everything else mentioned, I just need a dead simple way to open a full screen window that can only be closed by an escape sequence I define in code.我可以处理提到的所有其他事情,我只需要一种非常简单的方法来打开一个全屏窗口,该窗口只能由我在代码中定义的转义序列关闭。

I'm going for lowest hanging fruit here (Objective-C, C++, Java, python ruby, JavaScript hell whatever gets the job done quick and dirty.我要在这里寻找最低限度的果实(Objective-C、C++、Java、python ruby​​、JavaScript 地狱,无论是快速完成工作还是肮脏。

I read a primer on opening a full screen window in Objective-C but it can be closed really easily.我读了一篇关于在 Objective-C 中打开全屏窗口的入门书,但它可以很容易地关闭。 The point of this prank is to shame my co-worker for invading my computer for at least 10 or 20 seconds and I can't do that if he can just hit Appl-Q.这个恶作剧的目的是羞辱我的同事入侵我的电脑至少 10 或 20 秒,如果他只能点击 Appl-Q,我就不能这样做。

Happy Halloween!万圣节快乐!

To get something like this with a Cocoa app, you can place the following code in your app delegate's - (void)applicationDidFinishLaunching: (or similar):要使用 Cocoa 应用程序获得类似的内容,您可以将以下代码放在您的应用程序委托的- (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];

This will make a "kiosk" type app which can only be closed via the custom quit shortcut you set (or, you know, shutting down the computer forcibly).这将制作一个“信息亭”类型的应用程序,该应用程序只能通过您设置的自定义退出快捷方式关闭(或者,您知道,强行关闭计算机)。 The presentation options prevents the user from accessing the menu bar, dock, and app switching (via ⌘-Tab) or spaces, bringing up the force-quit window, or bringing up the shutdown/restart/sleep window.演示选项可防止用户访问菜单栏、停靠栏和应用程序切换(通过 ⌘-Tab)或空格、调出强制退出窗口或调出关机/重启/睡眠窗口。 Basically, make sure you set up a keyboard shortcut that you remember to terminate the app, otherwise, you're going to be locked out of your machine short of forcibly powering it off.基本上,请确保您设置了一个键盘快捷键,您记得要终止该应用程序,否则,如果没有强行关闭它,您将被锁定在您的机器之外。 It's a total PITA.这是一个完整的 PITA。

Of course, some of these customizations can be done in Interface Builder too (setting the key equivalent of the "Quit" menu item is easier there, and you can turn off the window's close control as well, as mentioned in comments above), but I just wanted to include this as code so it was more transparent (rather than uploading an Xcode project).当然,其中一些自定义也可以在 Interface Builder 中完成(设置“退出”菜单项的等效键在那里更容易,您也可以关闭窗口的关闭控件,如上面的评论中所述),但是我只是想把它作为代码包含进来,这样它就更透明了(而不是上传一个 Xcode 项目)。

Happy Halloween!万圣节快乐! 😈 😈

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM