在OS X上编写一个全屏不可关闭的窗口
Program a full screen uncloseable window on OS X
我们公司有一个游戏,如果你能从别人未解锁的电脑上给安全人员发一封电子邮件,你就能得到奖品。这个万圣节我要设一个陷阱。
我有一个叫做systems-engage
的简单程序,它启动一个键侦听器并以编程方式打开我的收件箱。当有人开始使用键盘时,我希望我的程序启动一个恐怖电影图像的全屏视觉攻击,伴随着极其响亮的尖叫。
我要用最容易摘到的果子(Objective-C, c++, Java, python, ruby, JavaScript等等,只要能快速完成任务就行。
我读了一篇关于在Objective-C中打开全屏窗口的入门文章,但它可以很容易地关闭。这个恶作剧的目的是让我的同事感到羞耻,因为他侵入了我的电脑至少10到20秒,如果他能按下apple - q键,我就做不到。
万圣节快乐!
要在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];
这将创建一个"kiosk";输入只能通过你设置的自定义退出快捷方式关闭的应用程序(或者,你知道,强制关闭计算机)。演示选项阻止用户访问菜单栏、dock和应用程序切换(通过⌘-Tab)或空格,调出强制退出窗口或调出关机/重新启动/睡眠窗口。基本上,确保你设置了一个键盘快捷键,你记得终止应用程序,否则,你将被锁定在你的机器,除非强行关闭它。这是一个完整的PITA。
当然,其中一些自定义也可以在Interface Builder中完成(设置键相当于"退出")。菜单项在那里更容易,你也可以关闭窗口的关闭控制,正如上面的评论所提到的),但我只是想把它作为代码包含,这样它就更透明了(而不是上传一个Xcode项目)。
万圣节快乐!
- 如何通过按下第三个窗口中的按钮,将QString从一个窗口获取到另一个窗口
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- GLEW/GLUT:调用init并创建一个窗口后,取消初始化并重新初始化?
- 如何将一个窗口保留在另一个应用程序窗口的前面
- Qt:从另一个窗口访问公共对象
- 触发另一个窗口的菜单按钮
- 如何在Qt中管理另一个窗口?
- 我在窗口中有一个fltk Fl_Choice下拉菜单,但只能通过鼠标使用
- 在SFML(C++)中启动一个新窗口
- 将变量从主窗口传递到另一个qt c++窗体
- 如何仅在一个窗口中忽略注入的输入?
- Gtkmm - 关闭窗口然后显示另一个窗口的正确方法
- 尝试使用 CPP 在一个 Qt 窗口中显示多个 png 文件
- 在C++中,系统如何将这些对象中的每一个与执行程序的窗口相关联?
- 有没有办法拿一个opencv显示窗口并将其保存到GUI窗口?
- 当电子的窗口隐藏时如何激活另一个应用程序窗口
- 发送到另一个窗口的鼠标移动消息不执行任何操作
- 两个窗口-一个由线程随机输出修改
- 在创建窗口(..)之后,如何给窗口一个颜色
- X11应用程序的最佳实践—每个应用程序或每个窗口一个XOpenDisplay