当我合上盖子或一段时间不活动后,Windows 7 会进入睡眠状态。很好。
我不希望它在合上盖子后立即进入睡眠状态;我希望它等待 5 分钟,然后然后去睡觉。
这能做到吗?
答案1
Windows 7 中没有内置此功能,我也不知道有哪个软件可以实现此功能(当然这并不意味着不存在这样的软件)。如果您具有编程能力(并且您的个人资料表明您在这方面并不逊色),那么这个 stackoverflow 问题将帮助您开始构建自己的软件:
https://stackoverflow.com/questions/3355606/detect-laptop-lid-closure-and-opening
简而言之:将 Windows 7 中的默认操作设置为不执行任何操作,但让您的程序作为服务运行并处理消息WM_POWERBROADCAST
。当您发现一个具有正确数据的程序时,请设置一个 5 分钟的计时器,并在计时器关闭时让机器进入睡眠状态。该消息上的不同数据或指示用户活动的消息(如 WM_MOUSEMOVE 或 WM_KEYDOWN)可能会取消计时器。
答案2
我正在寻找同样的东西(现在是 Windows 8.1)。联想的电源管理程序中曾经有一个实用程序可以做到这一点,但现在不再存在了(主要是因为 Windows 机器的启动速度比以前快得多)。
我目前正在考虑是否有一种方法可以创建一个由事件触发的计划任务,然后启动计时器,依此类推。
答案3
如果盖子保持关闭状态 1 分钟,以下 AutoHotkey 代码将使机器进入睡眠状态。您必须配置 Windows 电源设置,以便在盖子关闭时不执行任何操作。代码将检测盖子是否关闭,设置 60 秒的时间,如果盖子未重新打开,它将暂停计算机。
我大量使用了“Linear Spoon”提供的代码AutoHotkey 论坛。我的贡献是在靠近底部的几行。
#Persistent
MINUTES := 1
MinuteCount := 0
start_Lidwatcher()
/*
By Linear Spoon
7/28/2013
This script should work for Vista+
Details:
Use Start_LidWatcher to begin monitoring the lid state.
r := Start_LidWatcher()
When the state changes, the function "LidStateChange" will be called.
LidStateChange should have the following format:
LidStateChange(newstate)
{
...
}
newstate will be one of two values:
"opened" = The lid was opened
"closed" = The lid was closed
Note: It's possible that this function will be immediately called after
using Start_LidWatcher with the lid's current state (usually open).
When the application no longer needs to monitor the lid state,
call Stop_LidWatcher with the return value from Start_LidWatcher.
Pass it the return value from Start_LidWatcher.
Stop_LidWatcher(r)
*/
Start_LidWatcher()
{
VarSetCapacity(guid, 16)
;GUID_LIDSWITCH_STATE_CHANGE
Numput(0xBA3E0F4D, guid, 0, "uint"), Numput(0x4094B817, guid, 4, "uint")
Numput(0x63D5D1A2, guid, 8, "uint"), Numput(0xF3A0E679, guid, 12, "uint")
r := DllCall("RegisterPowerSettingNotification", "ptr", A_ScriptHwnd, "ptr", &guid, "uint", 0)
if (!r || ErrorLevel)
{
;MSDN says check GetLastError if the return value was NULL.
Msgbox % "RegisterPowerSettingNotification failed with error: " (ErrorLevel ? ErrorLevel : A_LastError)
return 0
}
OnMessage(0x218, "WM_POWERBROADCAST")
return r
}
Stop_LidWatcher(r)
{
DllCall("UnregisterPowerSettingNotification", "ptr", r)
OnMessage(0x218, "")
}
WM_POWERBROADCAST(wparam, lparam)
{
static fx := "LidStateChange"
if (wparam = 0x8013)
{
;data = 0 = closed
;data = 1 = opened
if isFunc(fx)
%fx%(Numget(lparam+20, 0, "uchar") ? "opened" : "closed")
}
return 1
}
/*
* The following code added by Kevin Kleinfelter. Copyright is in the public domain.
*/
LidStateChange(newstate)
{
Global MINUTES
Global MinuteCount
;msgbox, ding %newstate%
if (newstate = "opened") {
SetTimer, TickTock, off
}
if (newstate = "closed") {
MinuteCount := MINUTES
setTimer, TickTock, 60000
}
}
return
TickTock:
MinuteCount := MinuteCount - 1
if (MinuteCount <= 0) {
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 1, "int", 0)
}
return