Noob Posted December 20, 2006 Share Posted December 20, 2006 I suspect there may be a better way than just sending a keystroke or a mouse click every few minutes. I would like a PC to ignore its pre-set power scheme settings, and never go into standby/hibernate when a particular application is running (for example Notepad). I'm afraid that sending out keystrokes or mouse clicks may occasionally interfere with something. Any ideas would be greatly appreciated. Link to comment Share on other sites More sharing options...
herewasplato Posted December 20, 2006 Share Posted December 20, 2006 ...I'm afraid that sending out keystrokes or mouse clicks may occasionally interfere with something...Don't click, just "shake the mouse":While 1 If WinActive("Untitled - Notepad") Then $pos = MouseGetPos() MouseMove($pos[0], $pos[1] + 1, 0) MouseMove($pos[0], $pos[1], 0) EndIf Sleep(100000) WEnduntested [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
nfwu Posted December 20, 2006 Share Posted December 20, 2006 (edited) Correction: While 1 If WinActive("Untitled - Notepad") Then $pos = MouseGetPos() MouseMove($pos[0], $pos[1] + 1, 0) Sleep(500) MouseMove($pos[0], $pos[1], 0) Sleep(500) Else Sleep(100000) EndIf WEnd #) Edit: Corrected Then > Else (Thanks Valuater) Edited December 20, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Valuater Posted December 20, 2006 Share Posted December 20, 2006 Correction: While 1 If WinActive("Untitled - Notepad") Then $pos = MouseGetPos() MouseMove($pos[0], $pos[1] + 1, 0) Sleep(500) MouseMove($pos[0], $pos[1], 0) Sleep(500) Then Sleep(100000) EndIf WEnd #) ????? 8) Link to comment Share on other sites More sharing options...
nfwu Posted December 20, 2006 Share Posted December 20, 2006 The first code didn't work on my laptop. The second one did. Maybe this laptop is too slow..... #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Valuater Posted December 20, 2006 Share Posted December 20, 2006 The first code didn't work on my laptop. The second one did. Maybe this laptop is too slow..... #) Then Sleep(100000) EndIf wont work.... did you mean "Else" 8) Link to comment Share on other sites More sharing options...
nfwu Posted December 20, 2006 Share Posted December 20, 2006 Yes, thanks. Corrected. #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Noob Posted December 20, 2006 Author Share Posted December 20, 2006 This definitely beats the idea I originally had ! Thanks much! I just tested it and it works! Link to comment Share on other sites More sharing options...
herewasplato Posted December 20, 2006 Share Posted December 20, 2006 (edited) This definitely beats the idea I originally had ! Thanks much! I just tested it and it works!Great! @nfwu, Using Else like that would "shake the mouse" once per second while Notepad was active. I don't see the downside to having the Sleep line where I had it. I'm not offended in the least by your correction and I respect your coding skills, so please help me understand the rationale behind the Else. I'm sure I'm missing something. Edit: Did you try using your mouse while Notepad was active? It is pretty hard on my system:Run("notepad") WinWait("Untitled - Notepad") WinActivate("Untitled - Notepad") WinWaitActive("Untitled - Notepad") While 1 If WinActive("Untitled - Notepad") Then $pos = MouseGetPos() MouseMove($pos[0], $pos[1] + 1, 0) Sleep(500) MouseMove($pos[0], $pos[1], 0) Sleep(500) Else Sleep(100000) EndIf WEnd Thanks for your time... Edited December 20, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Stephen J Hart Posted March 4, 2007 Share Posted March 4, 2007 I suspect there may be a better way than just sending a keystroke or a mouse click every few minutes. I would like a PC to ignore its pre-set power scheme settings, and never go into standby/hibernate when a particular application is running (for example Notepad). I'm afraid that sending out keystrokes or mouse clicks may occasionally interfere with something. Any ideas would be greatly appreciated.Try this... AdlibEnable( "NoSleep", 50 * 1000 ); reset the standy-timer every 50 seconds Func NoSleep(); see the description of the SetThreadExecutionState function of kernel32.dll at http://msdn2.microsoft.com/en-us/library/aa373208.aspx Local Const $ES_DISPLAY_REQUIRED = 0x00000002; use this to zero the display's idle timer Local Const $ES_SYSTEM_REQUIRED = 0x00000001; use this to zero the system's idle timer Local Const $ES_CONTINUOUS = 0x80000000; add this to the other flag(s) to keep the display or system on until another call to SetThreadExecutionState with $ES_CONTINUOUS without the other flag(s) DllCall( "kernel32.dll", "int", "SetThreadExecutionState", "int", $ES_SYSTEM_REQUIRED ) EndFunc Link to comment Share on other sites More sharing options...
Creative Posted March 4, 2007 Share Posted March 4, 2007 Well, you could probably find the hybernation options in the registry...I feel that would be the most professional way and would prevent you from having to consantly run wakeup code. I'm not quite sure where it is...some possible locations are the contents of: HKEY_CURRENT_USER\Control Panel\Desktop HKEY_CURRENT_USER\Control Panel\PowerCfg HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Power They all look pretty interesting. "Everything is vague to a degree you do not realize till you have tried to make it precise." - Bertrand Russell [The Philosophy of Logical Atomism] Link to comment Share on other sites More sharing options...
Creative Posted March 4, 2007 Share Posted March 4, 2007 (edited) I did a registry scan before and after I changed the "hibernate" setting and I found that the only thing that changed was:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power\Heuristicswhose value changed as shown:05 00 00 00 00 01 01 00 ...05 00 00 00 00 01 00 00 ...So, I'd recommend either reading up on what the data of that key actually means or experimenting changing it around.In case you'd like to investigate, I used Registry Monitor a great free tool. Grab it here. Edited March 4, 2007 by Creative "Everything is vague to a degree you do not realize till you have tried to make it precise." - Bertrand Russell [The Philosophy of Logical Atomism] Link to comment Share on other sites More sharing options...
nfwu Posted March 4, 2007 Share Posted March 4, 2007 (edited) @nfwu, Using Else like that would "shake the mouse" once per second while Notepad was active. ... I'm sure I'm missing something.Nope, you're not missing something - it depends on what the OP wants - extra options are better. Maybe I shouldn't have stated that as a "Correction". Also, the applicaiton that the OP wants to prevent hibernation may have a logout after inactivity (sth like 1 minute - assuming it's a game), so it'll logoff after the 100 sec sleep completes. Edit: Did you try using your mouse while Notepad was active? It is pretty hard on my system:Eh, that can be corrected like this:Run("notepad") WinWait("Untitled - Notepad") WinActivate("Untitled - Notepad") WinWaitActive("Untitled - Notepad") While 1 If WinActive("Untitled - Notepad") Then $pos = MouseGetPos() MouseMove($pos[0], $pos[1] + 1, 0) Sleep(500) $pos = MouseGetPos() MouseMove($pos[0], $pos[1] - 1, 0) Sleep(500) Else Sleep(100000) EndIf WEnd @Creative: Tweaking registry settings without testing on multipule systems is risky. Unless, of course, the app will only be used on your own rig. #) Edited March 4, 2007 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
herewasplato Posted March 4, 2007 Share Posted March 4, 2007 @nfwu, Thanks for the reply. It is always fun to see & understand a bit of what others code & why. I should have thought of adding that second MouseGetPos. @Stephen, Nice. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Stephen J Hart Posted March 4, 2007 Share Posted March 4, 2007 Well, you could probably find the hybernation options in the registry...I feel that would be the most professional way and would prevent you from having to consantly run wakeup code.I'm not quite sure where it is...some possible locations are the contents of:HKEY_CURRENT_USER\Control Panel\DesktopHKEY_CURRENT_USER\Control Panel\PowerCfgHKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\PowerThey all look pretty interesting.But then if my code exits (or crashes) without resetting the registry entry I'd leave the user's system in a state they might dislike. Link to comment Share on other sites More sharing options...
Creative Posted March 4, 2007 Share Posted March 4, 2007 But then if my code exits (or crashes) without resetting the registry entry I'd leave the user's system in a state they might dislike.Proper coding can fix this.Tweaking registry settings without testing on multipule systems is risky. Unless, of course, the app will only be used on your own rig.Well, I know that works on XP, it wouldn't take much to check it for winME or something. Personally I think that the registry is good because it's not some peculiar roundabout way, as the others are. "Everything is vague to a degree you do not realize till you have tried to make it precise." - Bertrand Russell [The Philosophy of Logical Atomism] Link to comment Share on other sites More sharing options...
Stephen J Hart Posted March 5, 2007 Share Posted March 5, 2007 Proper coding can fix this.Really? Like how? For example, how will proper coding deal with a power failure during my script? I think it's better to accept that something can go wrong, and not mess around with the user's registry unless that's the only way.Well, I know that works on XP, it wouldn't take much to check it for winME or something. Personally I think that the registry is good because it's not some peculiar roundabout way, as the others are.In what way is a documented function in a Microsoft DLL "some peculiar roundabout way"? Link to comment Share on other sites More sharing options...
Creative Posted March 5, 2007 Share Posted March 5, 2007 Really? Like how? For example, how will proper coding deal with a power failure during my script? I think it's better to accept that something can go wrong, and not mess around with the user's registry unless that's the only way.Like, right after you change the registry you put a shortcut to a program which fixes the registry auto-startup, then, on the exit of your program, you delete this shortcut. So that, if you fail to get to that end, it'll always fix the registry on restart and in the probable case that nothing goes wrong, the shortcut is taken out at the end and the registry is simply returned to normal at the end.In what way is a documented function in a Microsoft DLL "some peculiar roundabout way"?I wasn't talking about that. Sorry should have been more clear. I was talking about the mousemove script by nfwu. "Everything is vague to a degree you do not realize till you have tried to make it precise." - Bertrand Russell [The Philosophy of Logical Atomism] Link to comment Share on other sites More sharing options...
Stephen J Hart Posted March 6, 2007 Share Posted March 6, 2007 Like, right after you change the registry you put a shortcut to a program which fixes the registry auto-startup, then, on the exit of your program, you delete this shortcut. So that, if you fail to get to that end, it'll always fix the registry on restart and in the probable case that nothing goes wrong, the shortcut is taken out at the end and the registry is simply returned to normal at the end.Ok, that is clever. But it seems quite complicated. And it'll trigger multiple alarms from my user's IDS/Firewall. And it makes testing harder: I'd have to force the failure and test the fix.I wasn't talking about that. Sorry should have been more clear. I was talking about the mousemove script by nfwu.Yup. And on my system that mouse-move stuff didn't actually prevent standby, plus it drove me crazy. Link to comment Share on other sites More sharing options...
Creative Posted March 6, 2007 Share Posted March 6, 2007 I'd imagine that it would. It reminds me of one time when I wrote a breakout clone and in order to keep it from getting stuck in a pattern (essentially ending playabilty of the level), I at one point figured whenever I detected a repeated path I'd just add one to the bearing of the ball...oh boy...big mistake...it reminds me how much a little tiny offset in the movement of anything can impact things. "Everything is vague to a degree you do not realize till you have tried to make it precise." - Bertrand Russell [The Philosophy of Logical Atomism] 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