Jump to content


Photo

Toggle allowing monitor power / screensaver for watching vid


  • Please log in to reply
2 replies to this topic

#1 toomanyplugs

toomanyplugs
  • Members
  • 3 posts

Posted 08 September 2008 - 06:18 PM

I'm trying to set up a script that will allow me to turn off screensaver/monitor power-off so that I can watch online video (Hulu or Netflix, eg) without having to reach over and shake the mouse every 10 minutes. I'd like to also turn it back on when I'm done (probably as a script exit action) in XP SP2.

I've looked at the tip listed here but it doesn't seem to work in XP, but that's ok because I can disable the screensaver with
RegWrite REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, ScreenSaveActive, 0

But this doesn't disable the monitor power off. I'd like an easy way to do this, too. I'd prefer to not have a loop sending Shift key or mouse movements repeatedly because sometimes that pops up the video control overlay and disrupts the experience.

I came across the SetThreadExecutionState function from MSDN. This seems to be exactly the right thing, so I tried to call it with a dllcall:

Res := DllCall("SetThreadExecutionState", UInt, 0x80000000, UInt, 0x00000002)  ; these parameters are for ES_CONTINUOUS and ES_DISPLAY_REQUIRED per MSDN

This doesn't prevent the monitor from turning off, and it returns (-2147483648), or 0xFFFFFFFF80000000. I'm not really sure what this means. Did the function execute correctly? MSDN says anything but a NULL return means ok execution, but the monitor still turns off!

I've tried every combination of Int, UInt, str, etc. to get it to work, no dice.


Sorry there's so much detail. All I really want is something simple, but I don't know enough of Windows API or ahk to get there.

#2 Serenity

Serenity
  • Members
  • 1271 posts

Posted 08 September 2008 - 06:51 PM

The ErrorLevel returned A4. This seems to work:

#Persistent
ES_CONTINUOUS := 0x80000000
ES_DISPLAY_REQUIRED := 0x00000002
SetTimer, Update, 60000
Return

Update:
DllCall("SetThreadExecutionState", UInt, ES_CONTINUOUS + ES_DISPLAY_REQUIRED)
Return


#3 toomanyplugs

toomanyplugs
  • Members
  • 3 posts

Posted 08 September 2008 - 08:17 PM

ah-hah! That's what I needed. It seems to work fine on my office computer. I can't wait to get home to try it out on my media center, thanks!