AutoHotkey Community

It is currently May 27th, 2012, 1:35 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: May 13th, 2009, 7: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.autohotkey.com/forum/viewtop ... 7049#67049 )

Enjoy!

Code:
#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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 5:20 pm 
Offline

Joined: March 19th, 2006, 5:52 am
Posts: 419
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.

Code:
#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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 5: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.

Code:
#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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2009, 7:13 am 
Offline

Joined: May 13th, 2009, 5:51 pm
Posts: 30
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!

Code:
#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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 7th, 2009, 9:35 pm 
Forgive me if this is a dumb question but what do we do with the script?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2009, 6:47 pm 
-tr wrote:
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. :?:


Report this post
Top
  
Reply with quote  
 Post subject: what to do with it...
PostPosted: June 9th, 2009, 7:51 pm 
Offline

Joined: May 13th, 2009, 5:51 pm
Posts: 30
...er, run it!
For myself I've compiled it and added it to my windows startup (compiled version here ). The footprint isnt too big, and I'll keep on it to see if I can make it smaller. I suppose if you dont want it "always on" you could write a shortcut to launch IE and this simultaneously. If you dont like the tray icon being there you could also remove the "Menu, Tray..." and "TrayTip..." lines. If anyone wants any extra features, etc just let me know.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 20th, 2009, 9:57 pm 
If you don't care about the tray icon the code could be much shorter...

Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#NoTrayIcon
#Persistent
ES_DISPLAY_REQUIRED := 0x00000002
SetTimer, CheckWindowsState, % 1000*30 ; Poll every 30 seconds

CheckWindowsState:
If ( WinActive("ahk_class AGFullScreenWinClass") || WinActive("ahk_class ShockwaveFlashFullScreen") )
{
   DllCall("SetThreadExecutionState", UInt, ES_DISPLAY_REQUIRED) ;prevent sleep
}
Return


I set this as one of my startup scripts. It works for flash or silverlight in fullscreen mode.


Report this post
Top
  
Reply with quote  
PostPosted: March 21st, 2010, 5:49 am 
Offline

Joined: March 21st, 2010, 5:46 am
Posts: 1
Location: Arlington, VA
Lafncow wrote:
...er, run it!
For myself I've compiled it and added it to my windows startup (compiled version here ). The footprint isnt too big, and I'll keep on it to see if I can make it smaller. I suppose if you dont want it "always on" you could write a shortcut to launch IE and this simultaneously. If you dont like the tray icon being there you could also remove the "Menu, Tray..." and "TrayTip..." lines. If anyone wants any extra features, etc just let me know.


DUDE!! THANK YOU!!!

we just signed up for netflix and then found this ridiculous bug in their viewer.

and 10 minutes later you solved it for us.

this site kicks major ass.

thanks again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2012, 11:44 pm 
Offline

Joined: March 4th, 2012, 11:39 pm
Posts: 2
First, thanks to all of you guys for all your work that makes life a bit easier.

Second, I've been using AHK for a while now, but I just couldn't get this one to work.

I copied it into a new script, ran it but it did not work. I even tried running it as admin but still no luck.

What do you guys think I'm doing wrong?

Please help me with this as it's driving me nuts having to push a button several times while watching a movie on Netflix. And I can't just disaple the screensaver completely as I need it.
I would really really appreciate any tips, thank you!

P.S. I'm using Vista 64.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2012, 6:31 am 
Offline

Joined: March 4th, 2012, 11:39 pm
Posts: 2
Any help guys, please?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group