如果盖子关闭,如何以编程方式从睡眠中唤醒? [英] How to wake from sleep programmatically if lid closed?

查看:29
本文介绍了如果盖子关闭,如何以编程方式从睡眠中唤醒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式将系统从睡眠中唤醒,有什么办法吗?

I want to wake system from sleep programmatically, is there any way to do this?

我已阅读以下链接:http://developer.apple.com/mac/library/qa/qa2004/qa1340.html

这里只说获取通知,不知道有没有什么办法可以唤醒系统?

this only talk about getting notification , but not sure is there any way to wake system from sleep?

我很欣赏这些信息的一些线索......

I appreciate some thread to the information...

更新:

根据我尝试使用 IOPMSchedulePowerEvent 的建议

As per the suggestion I tried with IOPMSchedulePowerEvent

我使用过的代码:

NSCalendarDate  *timeIntervalSinceNow = [NSCalendarDate dateWithTimeIntervalSinceNow:40];
IOReturn result = IOPMSchedulePowerEvent ((CFDateRef)timeIntervalSinceNow, NULL, CFSTR(kIOPMAutoWake)); 

结果:

如果盖子合上,它会在 MacBook 中失败

It fails in MacBook if lid closed

是我做错了什么还是有什么解决办法?

Am I doing some thing wrong or Any solution?

推荐答案

您可以通过电源管理器使用 IOPMSchedulePowerEvent 来安排唤醒事件.您可以安排立即唤醒.pmset 是一个命令行电源管理器的包装器.在某些情况下,您还可以使用 IOCancelPowerChange 防止睡眠.

You can schedule wake up events with IOPMSchedulePowerEvent through the power manager. You may be able to schedule an immediate wake up. pmset is a command line wrapper for the power manager. You can also prevent sleep with IOCancelPowerChange in certain cases.

您可以通过生成鼠标或按键事件来防止睡眠或唤醒.生成事件的一种方法是使用 CGPostKeyboardEvent.

You may be able to prevent sleep or wake up by generating a mouse or key event. One way to generate events is with CGPostKeyboardEvent.

正常睡眠与翻盖式封闭睡眠不同.要影响后者,您必须编写一个内核扩展,如 Insomnia.

Normal sleep is different from clamshell closed sleep. To affect the latter you must write a kernel extension like Insomnia.

这篇关于如果盖子关闭,如何以编程方式从睡眠中唤醒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆