Jump to content

Recommended Posts

Posted

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.

Posted

...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)
WEnd
untested

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted (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 by nfwu
Posted (edited)

This definitely beats the idea I originally had :P ! 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 by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

  • 2 months later...
Posted

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
Posted

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]

Posted (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\Heuristics

whose 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 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]

Posted (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 by nfwu
Posted

@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]

Posted

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.

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.
Posted

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]

Posted

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"?
Posted

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]

Posted

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.
Posted

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]

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...