Jump to content


Netflix Silverlight Screen Saver Disabler


  • Please log in to reply
6 replies to this topic

#1 Lafncow

Lafncow
  • Guests

Posted 13 May 2009 - 06:29 AM

This turns the screen saver off when you watch a Netflix streaming movie, then turns it back on when you're done. Fall asleep while watching? No prob, it bumps the screen saver back on after 2.5 hours! Does exactly what MS should have done in the first place! ;)
Should work with any browser.

Pretty simple stuff, lifted the real goods from SKAN (thank you!) ( http://www.autohotke... ... 7049#67049 )

Enjoy!

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Menu, Tray, Icon, User32.dll, 7
Loop
{
WinWaitActive, Netflix: Netflix Movie Viewer
{
	Gosub, Netfix
}

WinWaitNotActive, Netflix: Netflix Movie Viewer
{
	Gosub, ScreenSaveActivate
}
}

Netfix:
Menu, Tray, Icon, User32.dll, 2
TrayTip, Netfix, Screen Saver Disabled`, Enjoy The Show!, 10, 2
DllCall("SystemParametersInfo", Int,17, Int,0, UInt,NULL, Int,2) ;disable screensaver
SetTimer, CheckScreenSaveActive, 999
SetTimer, ScreenSaveActivate, -9000000 ;run only once
Return

CheckScreenSaveActive:
DllCall("SystemParametersInfo", Int,16, UInt,NULL, "UInt *",SSACTIVE, Int,0) ;check
If SSACTIVE
{
   DllCall("SystemParametersInfo", Int,17, Int,0, UInt,NULL, Int,2) ;disable
}
Return

ScreenSaveActivate:
Menu, Tray, Icon, User32.dll, 7
SetTimer, CheckScreenSaveActive, OFF
SetTimer, ScreenSaveActivate, OFF
DllCall("SystemParametersInfo", Int,17, Int,1, UInt,NULL, Int,2) ;enable
TrayTip, Netxfix, Screen Saver Enabled!, 10, 1
Return

OnExit, ExitSub

ExitSub:
Gosub, ScreenSaveActivate
ExitApp


#2 TheIrishThug

TheIrishThug
  • Members
  • 419 posts

Posted 13 May 2009 - 04:20 PM

The way you wrote it, you are going to do the Netflix many many times while you are watching the movie. I added a variable to save the state so there is much less excess work. I also used a timer instead of a never ending loop, again it means less work (and I think it looks cleaner). I made the sleep timer a variable so that it is easier to change if need be. If you do have the screen saver activated by the sleep timer, you will need to reset the state with the hotkey when you wake up.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.

windowsState := 0
sleepDelay := 150 ; mins
Menu, Tray, Icon, user32.dll, 7
SetTimer, CheckWindowsState, 1000
OnExit, ExitSub

;reset the window state after the sleep timer hits.
^#R::windowsState := 0

CheckWindowsState:
If (!windowsState && WinActive("Netflix: Netflix Movie Viewer"))
{
	windowsState := 1
	Menu, Tray, Icon, user32.dll, 2
	TrayTip, Netfix, Screen Saver Disabled`, Enjoy The Show!, 10, 2
	DllCall("SystemParametersInfo", Int,17, Int,0, UInt,NULL, Int,2) ;disable screensaver
	SetTimer, ScreenSaveActivate, % -sleepDelay * 60*1000 ;run only once
}
Else If (windowsState && !WinActive("Netflix: Netflix Movie Viewer"))
{
	windowsState := 0
	SetTimer, ScreenSaveActivate, -1 ; run sub and turn off the timer
}
Return

ScreenSaveActivate:
Menu, Tray, Icon, user32.dll, 7
DllCall("SystemParametersInfo", Int,17, Int,1, UInt,NULL, Int,2) ;enable screensaver
TrayTip, Netxfix, Screen Saver Enabled!, 10, 1
Return

ExitSub:
Gosub, ScreenSaveActivate
ExitApp


#3 Lafncow

Lafncow
  • Guests

Posted 13 May 2009 - 04:33 PM

Nice! Thank you, much cleaner. I had originally tried a similar approach but couldnt get it right so fell back on the dumb loop. While we're talking about things I did wrong... I wrote this in Win 7, however the user32.dll icon #7 doesnt exist in XP. Here's your rewrite plus the icon fix for XP. Cheers.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.

windowsState := 0
sleepDelay := 150 ; mins
Menu, Tray, Icon, SHELL32.dll, 44
SetTimer, CheckWindowsState, 1000
OnExit, ExitSub

;reset the window state after the sleep timer hits.
^#R::windowsState := 0

CheckWindowsState:
If (!windowsState && WinActive("Netflix: Netflix Movie Viewer"))
{
   windowsState := 1
   Menu, Tray, Icon, user32.dll, 2
   TrayTip, Netfix, Screen Saver Disabled`, Enjoy The Show!, 10, 2
   DllCall("SystemParametersInfo", Int,17, Int,0, UInt,NULL, Int,2) ;disable screensaver
   SetTimer, ScreenSaveActivate, % -sleepDelay * 60*1000 ;run only once
}
Else If (windowsState && !WinActive("Netflix: Netflix Movie Viewer"))
{
   windowsState := 0
   SetTimer, ScreenSaveActivate, -1 ; run sub and turn off the timer
}
Return

ScreenSaveActivate:
Menu, Tray, Icon, SHELL32.dll, 44
DllCall("SystemParametersInfo", Int,17, Int,1, UInt,NULL, Int,2) ;enable screensaver
TrayTip, Netxfix, Screen Saver Enabled!, 10, 1
Return

ExitSub:
Gosub, ScreenSaveActivate
ExitApp


#4 Lafncow

Lafncow
  • Members
  • 30 posts

Posted 14 May 2009 - 06:13 AM

I hadnt tested it yet, having done so now I think you need #Persistent in there to keep the script from ending (and dropping the timers). Also, I added the timer to timeout and made it just give the message box, that trips the checkwindowstate and lets your screensaver activate without being a totally annoyance on the off chance that you're still watching :) .
I think this is a keeper, anyone? Again big thanks to TheIrishThug for making this much more sensible & tidy.

Update: Tested in XP & Windows 7; success!
Solved previous issues of not detecting netflix's fullscreen mode and of not preventing monitor power down/sleep/standby mode. The fix for the 2nd issue comes from here. The fix for the first issue is admittedly still noob-ish since it simply looks for a "AGFullScreenWinClass" window concurrent with the netflix window and I doubt that ahk_class is unique to netflix. Unfortunately the fullscreen window is titleless. I'm certain there's a way to grab the unique ID of the AGFullScreenWinClass window opened by netflix, but I left it as is for the sake of simplicity & performance (ok, and a bit of laziness too) ...still it seems "false positives" would be very rare.
Anyway, enjoy!

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
ES_CONTINUOUS := 0x80000000
ES_DISPLAY_REQUIRED := 0x00000002
windowsState := 0
sleepDelay := 150 ; mins
Menu, Tray, Icon, SHELL32.dll, 44
SetTimer, CheckWindowsState, 1000
OnExit, ExitSub

CheckWindowsState:
If ((!windowsState && WinActive("Netflix: Netflix Movie Viewer")) || (!windowsState && WinExist("Netflix: Netflix Movie Viewer") && WinActive("ahk_class AGFullScreenWinClass")))
{
   windowsState := 1
   Menu, Tray, Icon, user32.dll, 2
   TrayTip, Netfix, Screen Saver Disabled`, Enjoy The Show!, 10, 2
   DllCall("SystemParametersInfo", Int,17, Int,0, UInt,NULL, Int,2) ;disable screensaver
   DllCall("SetThreadExecutionState", UInt, ES_CONTINUOUS + ES_DISPLAY_REQUIRED) ;prevent sleep
   SetTimer, NetflixTimeOut, % -sleepDelay * 60*1000 ;run only once
}
Else If ((windowsState && !WinActive("Netflix: Netflix Movie Viewer")) || (windowsState && !WinExist("Netflix: Netflix Movie Viewer")))
{
   SetTimer, ScreenSaveActivate, -1 ; run sub and turn off the timer
}
Return

ScreenSaveActivate:
Menu, Tray, Icon, SHELL32.dll, 44
TrayTip, Netfix, Screen Saver Enabled!, 10, 1
DllCall("SystemParametersInfo", Int,17, Int,1, UInt,NULL, Int,2) ;enable screensaver
DllCall("SetThreadExecutionState", UInt, ES_CONTINUOUS) ;enable sleep
SetTimer, NetflixTimeOut, OFF
windowsState := 0
Return

NetflixTimeOut:
MsgBox, Zzzzzzzz...
Return

ExitSub:
Gosub, ScreenSaveActivate
ExitApp


#5 -tr

-tr
  • Guests

Posted 07 June 2009 - 08:35 PM

Forgive me if this is a dumb question but what do we do with the script?

#6 Valiant

Valiant
  • Guests

Posted 09 June 2009 - 05:47 PM

Forgive me if this is a dumb question but what do we do with the script?


I would also like to ask the dumb question. :?:

#7 SheridanZhoy

SheridanZhoy
  • Members
  • 1 posts

Posted 30 January 2013 - 04:15 AM

Forgive me if this is a dumb question but what do we do with the script?

I know this thread is quite old, but it's best not to leave these questions unanswered.

 

This is an AutoHotkey script. You will need to install AutoHotkey (http://l.autohotkey....y_L_Install.exe), copy the above script to a text editor, and save as *.ahk to run the script.