如何以编程方式从睡眠中唤醒? [英] How to wake from sleep programmatically?

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

问题描述



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



这只谈谈获得通知,但不确定是否有任何方法让系统从睡眠中唤醒?



我感谢一些线程的信息...



更新: b
$ b

根据我的建议,我尝试使用IOPMSchedulePowerEvent



代码我使用了:

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

结果:



解决方案

如果lid关闭了



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



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



编辑:



正常睡眠不同于蛤壳式睡眠。要影响后者,您必须编写内核扩展程序,如失眠


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

I have read following link: 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...

Update:

As per the suggestion I tried with IOPMSchedulePowerEvent

Code I have used:

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

Result:

It fails in MacBook if lid closed

Am I doing some thing wrong or Any solution?

解决方案

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.

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.

Edit:

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

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

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