Thanks Beholder for your kind help !
I retested without success a modified script (hope it is OK, I have no experience with AHK scripts yet) that should show a message box when the power button is pressed :
Code: Select all
OnMessage(0x218, "WM_POWERBROADCAST")
WM_POWERBROADCAST(wParam, lParam)
{
If wParam=0
{
MsgBox, PowerButton pressed !
Return 0x424D5144
}
Else
{
MsgBox, PowerButton pressed !
Return
}
}
Results : if the sleep button is configured as sleep or hibernate, the computer does sleep/hibernate. When the button is configured as "Do nothing" then nothing happens. In neither of the three cases I saw a message box pop up.
I read in
this thread on the AHK forum that that in Windows Vista it is probably impossible to interrupt the hibernation event with the 0x424D5144 message. I guess it is the same problem with Windows 7. Looks like I am stuck, should have stayed with XP
Edit: I found out after some more reading (e.g.
here) that in fact Vista does not deliver the PBT_APMQUERYSUSPEND event (and therefore the event can't be blocked by BROADCAST_QUERY_DENY= 0x424D5144). The only remaining way to influence suspend/hibernate/sleep behavior is SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED), but this function will only reset the idle timer and thus prevent the system from going to sleep due to an idle timeout. It does not help to block a power button event.
