10.6 中锁定屏幕

发布于 2024-08-19 22:37:32 字数 148 浏览 3 评论 0原文

我将如何像钥匙串那样锁定屏幕,这意味着阻止对 Dock、菜单栏、桌面等的所有访问。基本上只是一个黑屏,我可以在其中添加密码字段,以便用户返回桌面?我很了解 Carbon 方法,但我想要 NSApplication 方法,因为这是一个全 Cocoa 应用程序。

谢谢~

How would I go about locking a screen like Keychain does, meaning preventing all access to Dock, menubar, desktop, etc. Basically just a black screen that I can add a password field to, for the user to return to the desktop? I am well aware of the Carbon method, but I want the NSApplication method because this is an all Cocoa application.

Thanks~

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海的爱人是光 2024-08-26 22:37:32

如果您可以不用自己编写这段代码,那就更好了。考虑到多年来在屏幕锁定代码中发现的漏洞数量,编写自己的代码来锁定屏幕通常是一个糟糕的主意。如果您有一个 Carbon 调用可以做到这一点,请继续使用它......不要担心 Cocoa 代码的“纯度”。

但是,如果您决定自己编写此代码,则需要执行以下操作:

首先,使用 CoreGraphics 捕获所有屏幕。请参阅:http://developer.apple.com /mac/library/documentation/GraphicsImaging/Conceptual/QuartzDisplayServicesConceptual/Articles/DisplayCapture.html

接下来,创建一个新的 NSWindow 并将其放在用于捕获屏幕的窗口前面。您必须调用 CG 函数来获取覆盖每个屏幕的黑色窗口的“顺序”,并将新窗口排序在该窗口前面。通常情况下,黑色窗口的顺序很远,一切都在它后面。在窗口中输入密码字段。请勿使用普通文本字段或编写自己的代码来输入密码。密码输入字段中有大量特殊代码,因此您无法从中复制文本,并且当您在密码字段中输入内容时,其他程序无法侦听击键。因此,请使用 Apple 提供的一款。

最后,将计算机置于“kiosk 模式”。此模式允许您禁用 alt-tab、用户切换、菜单栏和扩展坞,甚至强制退出的功能。请参阅:http://developer.apple.com/mac/library /technotes/KioskMode/Introduction/Introduction.html

这不是很多代码,它只是使用了一些不同的 API,因此您将花费大部分时间在 API 文档之间切换。我建议将屏幕锁定代码编写为自己的应用程序(只需将新的应用程序目标添加到您的 Xcode 项目中),然后将屏幕锁定器放入您的应用程序包中。这曾经是(从 10.4 开始)Apple Remote Desktop 实现“锁定屏幕”功能的方式,但我再也找不到该应用程序了。

If you can get away with not writing this code yourself, all for the better. It is usually a terrible idea to write your own code to lock the screen, considering the number of vulnerabilities that have been found in screen locking code over the years. If you have a Carbon call that can do it, go ahead and use that... don't worry about the "purity" of your Cocoa code.

However, if you decide to write this yourself, here's what you do:

First, capture all the screens using CoreGraphics. See: http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/QuartzDisplayServicesConceptual/Articles/DisplayCapture.html

Next, create a new NSWindow and put it in front of the window that's used for capturing the screens. You'll have to call a CG function to get the "order" of the black window covering each screen, and order the new window in front of that. Normally, the black window has an order so far forward that everything is behind it. Put a password field in the window. Do NOT use an ordinary text field or write your own code for password input. The password input field has a ton of special code in it so you can't copy text out of it, and other programs can't listen to keystrokes while you're typing into a password field. So use the one that Apple provides.

Last, put the computer in "kiosk mode". This mode allows you to disable alt-tab, user switching, the menubar and dock, and even the ability to force quit. See: http://developer.apple.com/mac/library/technotes/KioskMode/Introduction/Introduction.html

It's not a lot of code, it just uses a few different APIs so you'll spend most of your time bouncing between API docs. I suggest writing the screen lock code as its own application (just add a new application target to your Xcode project) and then put the screen locker inside your application bundle. This used to be (as of 10.4) how Apple Remote Desktop implemented the "Lock Screen" functionality, but I can't find the app anymore.

等往事风中吹 2024-08-26 22:37:32

我相信 Cocoa 可以替代 SetSystemUIMode< /a> API 直到 10.6 才引入。

如果您可以接受仅限 Snow-Leopard 的代码,答案是 - setPresentationOptions:NSApplication 上。

I believe the Cocoa replacement to the SetSystemUIMode API was not introduced until 10.6.

If you can live with Snow-Leopard-only code, the answer is - setPresentationOptions: on NSApplication.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文