Xichael Posted January 31, 2012 Share Posted January 31, 2012 (edited) While 1 Sleep(50) Opt("WinTitleMatchMode") If WinExists("Netflix") Then DllCall("Kernel32.dll","int","SetThreadExecutionState","int",0x80000000,"int",0x00000002) WinWaitClose("Netflix") EndIf WEndNetflix isn't keeping the screen awake while watching videos, but fortunately there's SetThreadExecutionState. It says I'll need both ES_CONTINUOUS and ES_DISPLAY_REQUIRED for it to work. Am I correct that in the DllCall those would have to be 0x80000000 and 0x00000002, respectively?What am I doing wrong here? This script it crashing AutoIt entirely, with no error message whatsoever.[Edited Title] Edited January 31, 2012 by Xichael Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 31, 2012 Share Posted January 31, 2012 (edited) It's probably crashing because of that extra imaginary parameter you added. Read the docs again. Try something like "int", 0x80000000 + 0x00000002 (not tested) Edited January 31, 2012 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
kylomas Posted January 31, 2012 Share Posted January 31, 2012 Xichael, Did you start Netflix within the same process that is issueing setthreadexecutionstate? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Xichael Posted January 31, 2012 Author Share Posted January 31, 2012 (edited) It's probably crashing because of that extra imaginary parameter you added. Read the docs again. Try something like "int", 0x80000000 + 0x00000002 (not tested) Thanks. It's not crashing now. I was wondering how to put the two together. I couldn't find anything in the docs about it. So, it's a "+" to put two parameters in one? Did you start Netflix within the same process that is issueing setthreadexecutionstate? No. How would I do that? I'm opening Netflix in Chrome, which has a process per tab and then some. How do you have a process issue a dll? Is it necessary for my purposes? As you may gather, I'm new to all of this, and programming in general, so I'll take all the guidance I can get. Edited January 31, 2012 by Xichael Link to comment Share on other sites More sharing options...
kylomas Posted January 31, 2012 Share Posted January 31, 2012 Xichael, If your problem is that the sreen is being powered off, change the power scheme. I'm not sure that this function has anything to do with keeping your screen on, however, I'm new to Windows programming also so maybe an expert will weigh in. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Xichael Posted January 31, 2012 Author Share Posted January 31, 2012 (edited) change the power scheme That's how I was originally doing it, but I wanted it to work with any power scheme without needing any tweaking to correctly reset the sceme after Netflix is closed. Here's what I was using: Local $Ran While 1 Sleep(50) If WinExists("Netflix - Google Chrome") and $Ran=0 Then Run("powercfg -change -monitor-timeout-ac 0") $Ran=1 ElseIf WinWaitClose("Netflix - Google Chrome") and $Ran=1 Then Run("powercfg -change -monitor-timeout-ac 5") $Ran=0 EndIf WEnd Then I read about SetThreadExecutionState, and it seems like a better way to do it, if I can get it working properly. This works well, but it's perpetually doing the DllCall, over and over. I'm just worried that it's bad for some reason; like it's wearing out poor Kernel32:While 1 Sleep(50) Opt("WinTitleMatchMode") If WinExists("Netflix") Then DllCall("Kernel32.dll","int","SetThreadExecutionState","int",0x00000002) EndIf WEnd There must be good reasons I shouldn't do it this way, right? Edited January 31, 2012 by Xichael Link to comment Share on other sites More sharing options...
kylomas Posted January 31, 2012 Share Posted January 31, 2012 Xichael, And that worked? I don't see how the 1st if is ever true.. IF you are using $Ran as a toggle variable than declare it like local $Ran = 0 kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Xichael Posted January 31, 2012 Author Share Posted January 31, 2012 Ok, just reading up on it. It's called an initializer? It says it's required, but I haven't used it before. I guess when it's not declared, it defaults to 0? Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 31, 2012 Share Posted January 31, 2012 Ok, just reading up on it. It's called an initializer? It says it's required, but I haven't used it before. I guess when it's not declared, it defaults to 0? Almost. With a simple script test we can prove that it's an empty string. Like if you had used $vTest = "" Local $vTest ConsoleWrite(VarGetType($vTest) & @LF) ConsoleWrite(StringLen($vTest) & @LF) And that worked? I don't see how the 1st if is ever true.. IF you are using $Ran as a toggle variable than declare it like local $Ran = 0 Well, yes. ConsoleWrite(("" = 0) & @LF) But I would still set it to = 0 to look consistent and avoid the behind the scenes convert. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 31, 2012 Share Posted January 31, 2012 Thanks. It's not crashing now.I was wondering how to put the two together. I couldn't find anything in the docs about it. So, it's a "+" to put two parameters in one?There is only one parameter!EXECUTION_STATE WINAPI SetThreadExecutionState(__in EXECUTION_STATE esFlags);Count that. One. That's all.As for the flags, if you want for example ES_SYSTEM_REQUIRED (1) and ES_DISPLAY_REQUIRED (2), then yeah, you add* them together (1+2). How else would you get to 3?*Well, the article tells you to use BitOr() ("This parameter can be one or more of the following values."), for the thinking behind that, see Setting Styles in the wiki. But the world will not end if you just add them in this case as the numbers are unique. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Xichael Posted January 31, 2012 Author Share Posted January 31, 2012 Flags. That's the term I was looking for. Still new to all the nomenclature. What's the "es" in esFlags? And they seem to be referring to the same thing as Styles in the article. Are Flags Styles? The article also mentions that "+" and BitOR will return different results. Looks like BitOR is the way to go. I appreciate all the insight, Admiral. Thanks. Link to comment Share on other sites More sharing options...
jaberwacky Posted January 31, 2012 Share Posted January 31, 2012 (edited) I imagine that this would take care of the endless calls to run:Global Const $program_name = "Netflix - Google Chrome" While True If WinExists($program_name) Then Run("powercfg -change -monitor-timeout-ac 0") While True If Not WinExists($program_name) Then Run("powercfg -change -monitor-timeout-ac 5") ExitLoop EndIf Sleep(50) WEnd EndIf Sleep(50) WEnd Edited January 31, 2012 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 31, 2012 Share Posted January 31, 2012 You could say that Styles are Flags yes. I'm guessing es means ExecutionState .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Xichael Posted January 31, 2012 Author Share Posted January 31, 2012 LaCastiglioneI imagine that this would take care of the endless calls to run...I was actually referring to the second script in the post. That first one was working fine; just not the best approach. Thanks for showing me another way of doing things though.That BitOR is doing it's job quite nicely keeping the screen awake. However, after Netflix closes, it's not turning off again. The documentation says:ES_CONTINUOUS 0x80000000 Informs the system that the state being set should remain in effect until the next call that uses ES_CONTINUOUS and one of the other state flags is cleared.So I suppose I need to clear the flags? How would I do that? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now