Writing a Simple AutoHotkey Script (press a key every X second on desktop)

autohotkey

I need to press any useless key (like F11) every 5 minutes or less to keep the windows active (if it became inactive for 5 minutes it will lock-out).

But I need the key to be pressed on the desktop (so it doesn't effect any open windows).

I have tried

Loop
{
   ControlSend, {F11}, WindowsApplication1
   Sleep, 100000
}

but doesn't seem to work.

thanks.

Best Answer

Why do you want to send F11 to the desktop?
If it's just to keep your computer awake you can use the following script:

#SingleInstance, force
#Persistent
SetTimer, NoSleep, 30000
Return

NoSleep:
 DllCall( "SetThreadExecutionState", UInt,0x80000003 )
Return

From Microsoft:

SetThreadExecutionState function
Enables an application to inform the system that it is in use, thereby preventing the system from entering sleep or turning off the display while the application is running.


It is also possible to emulate mouse-action to keep the system from sleeping
(if above script somehow doesn't work for you):

Loop {
    Sleep, 30000
    MouseMove, 1, 0, 1, R  ;Move the mouse one pixel to the right
    MouseMove, -1, 0, 1, R ;Move the mouse back one pixel
}

So there would be no need to emulate actually pressing a key.

Related Question