Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Keep Alive! Script


  • Please log in to reply
3 replies to this topic
Jstjacques
  • Members
  • 112 posts
  • Last active: May 12 2014 09:43 PM
  • Joined: 10 Jan 2013

I mostly use AHK within a VM on my work machine and then continue with my other work on another screen.  The only drawback to this is when I leave my computer, if it locks or sleeps the VM also shuts down and kills the script.  As a result, I made a simple keep alive script that allows me to leave the desk and not worry about the computer sleeping.  I also added a simple password protect in case a co-worker tries to play a prank while I was away.

 

So, before anyone asks, I can't just change when the computer locks/sleeps, IT controls that.  Also, I know the protection isn't great, but a super hacker most likely won't find my desk in the 10-30 minutes I'm away.  tongue.png

 

EDIT: I changed up the script to check and account for different monitor sizes and numbers.  Also, it takes 4 random images (that you need to add for this to work!tongue.png ) and randomly places them around the screen every 5 seconds.

 

Enjoy!

##SingleInstance Force
Inputbox, Loop, Loop number, How long should screen saver run? (in minutes).
if (Errorlevel)
{
  msgbox, You didn't enter a number.
  Exitapp
}
If (Loop = "")
{
  msgbox, You didn't enter a number. Value assumed to be 1 Minute
  Loop = 1
}
Inputbox, PW, Password, Enter Password to secure Keep Alive or cancel for none, HIDE
count = 1
Loop := Loop * 6
Blockinput, mousemove
BlockKeyboardInputs("On")
SysGet, MonitorX, MonitorCount
MonCount = 1
MonW = 0
MonH = 0
Loop, %MonitorX%
{
  SysGet, Mon%Moncount%, Monitor, %Moncount%
  MonWTemp := Mon%Moncount%Right - Mon%Moncount%Left
  MonW := MonW + MonWTemp
  MonHTemp := Mon%Moncount%Bottom
  IfGreater, MonHTemp, %MonH%
  {
    MonH = %MonHTemp%
  }
  MonCount++
}
Random, RNDX, 1, %MonW%
Random, RNDY, 1, %MonH%
Gui, 1:Color, Black
Gui, 1:-border -caption
Gui, 1:Add, Picture,x%RNDX% y%RNDY% vaccruent,accruent.png ;Add your own Image file***
Random, RNDX, 1, %MonW%
Random, RNDY, 1, %MonH%
Gui, 1:Add, Picture,x%RNDX% y%RNDY% vSprite1,Sprite1.png ;Add your own Image file***
Random, RNDX, 1, %MonW%
Random, RNDY, 1, %MonH%
Gui, 1:Add, Picture,x%RNDX% y%RNDY% vSprite2,Sprite2.png ;Add your own Image file***
Random, RNDX, 1, %MonW%
Random, RNDY, 1, %MonH%
Gui, 1:Add, Picture,x%RNDX% y%RNDY% vSprite3,Sprite3.png ;Add your own Image file***
Gui, 1:Show, x0 y0 h%MonH% w%MonW%, KeepAlive
MonW := MonW - 200
MonH := MonH - 200
Loop, %Loop%
{ 
  Sleep, 5000 
  Random, RNDX, 1, %MonW%
  Random, RNDY, 1, %MonH%
  Guicontrol, 1:Movedraw, accruent, x%RNDX% y%RNDY%
  Random, RNDX, 1, %MonW%
  Random, RNDY, 1, %MonH% 
  Guicontrol, 1:Movedraw, Sprite1, x%RNDX% y%RNDY%
  Random, RNDX, 1, %MonW%
  Random, RNDY, 1, %MonH% 
  Guicontrol, 1:Movedraw, Sprite2, x%RNDX% y%RNDY%
  Random, RNDX, 1, %MonW%
  Random, RNDY, 1, %MonH% 
  Guicontrol, 1:Movedraw, Sprite3, x%RNDX% y%RNDY%
  MouseGetPos, Outx, Outy
  Outx := Outx + 10
  Outy := Outy + 10
  Mousemove,  %outX%,  %OutY%
  Sleep, 5000
  Random, RNDX, 1, %MonW%
  Random, RNDY, 1, %MonH%
  Guicontrol, 1:Movedraw, accruent, x%RNDX% y%RNDY%
  Random, RNDX, 1, %MonW%
  Random, RNDY, 1, %MonH% 
  Guicontrol, 1:Movedraw, Sprite1, x%RNDX% y%RNDY%
  Random, RNDX, 1, %MonW%
  Random, RNDY, 1, %MonH% 
  Guicontrol, 1:Movedraw, Sprite2, x%RNDX% y%RNDY%
  Random, RNDX, 1, %MonW%
  Random, RNDY, 1, %MonH% 
  Guicontrol, 1:Movedraw, Sprite3, x%RNDX% y%RNDY%
  MouseGetPos, Outx, Outy
  Outx := Outx - 10
  Outy := Outy - 10
  Mousemove,  %outX%,  %OutY% 
  Count := Count + 1
}
Gui, 1:Destroy
BlockInput, Off
BlockKeyboardInputs("Off")
msgbox,262144,, Screen Saver Exiting!,5
ExitApp
Esc::
BlockInput, Off
BlockKeyboardInputs("Off")
If (PW = "")
{
  msgbox,262144,, Screen Saver Exiting!,1
  Splashtextoff
  BlockInput, off
  BlockKeyboardInputs("Off")
  Exitapp
}
Inputbox, Password, Password, Enter Password to disable the Screen Saver,HIDE,200,150,0,0
IfEqual, Password, %PW%
{
 msgbox,262144,, Screen Saver Exiting!,1
 Splashtextoff
 BlockInput, off
 BlockKeyboardInputs("Off")
 Exitapp
}
Else
{
  msgbox,262144,, Screen Saver Continues!,1
  BlockKeyboardInputs("On")
  Blockinput, mousemove
}
; From http://www.autohotkey.com/forum/topic22761.html
BlockKeyboardInputs(state = "On")
{
   static keys
   keys=Space,Enter,Alt,Tab,BackSpace,Del,Ins,Home,End,PgDn,PgUp,Up,Down,Left,Right,CtrlBreak,ScrollLock,PrintScreen,CapsLock
,Pause,AppsKey,LWin,LWin,NumLock,Numpad0,Numpad1,Numpad2,Numpad3,Numpad4,Numpad5,Numpad6,Numpad7,Numpad8,Numpad9,NumpadDot
,NumpadDiv,NumpadMult,NumpadAdd,NumpadSub,NumpadEnter,NumpadIns,NumpadEnd,NumpadDown,NumpadPgDn,NumpadLeft,NumpadClear
,NumpadRight,NumpadHome,NumpadUp,NumpadPgUp,NumpadDel,Media_Next,Media_Play_Pause,Media_Prev,Media_Stop,Volume_Down,Volume_Up
,Volume_Mute,Browser_Back,Browser_Favorites,Browser_Home,Browser_Refresh,Browser_Search,Browser_Stop,Launch_App1,Launch_App2
,Launch_Mail,Launch_Media,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22
,1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
,²,&,é,",',(,-,è,_,ç,à,),=,$,£,ù,*,~,#,{,[,|,``,\,^,@,],},;,:,!,?,.,/,§,<,>,vkBC
   Loop,Parse,keys, `,
      Hotkey, *%A_LoopField%, KeyboardDummyLabel, %state% UseErrorLevel
   Return
KeyboardDummyLabel:
Return
}
; From http://www.autohotkey.com/forum/topic22761.html

You can get a good look at a steak but shoving your head up a cow's rear end, but wouldn't you rather take the butchers word for it?


robert_ilbrink
  • Members
  • 561 posts
  • Last active: Nov 07 2019 05:14 PM
  • Joined: 05 May 2012

Wow, I did it this way. 1 Pixel is often enough not to go to sleep, and does not hinder me during work. I can toggle this anyway. This is started by a SetTimer, MoveMouse, 60000 and stopped with SetTimer, MoveMouse, Off

MoveMouse:
    MouseMove, 1, 0, 1, R ;Move the mouse one pixel to the right
	Sleep, 50 ; Wait 50 ms. Not realy required, but makes the move visible
    MouseMove, -1, 0, 1, R ;Move the mouse back one pixel
return


Jstjacques
  • Members
  • 112 posts
  • Last active: May 12 2014 09:43 PM
  • Joined: 10 Jan 2013

The reason I added the splashtext was so that others know why my computer is unlocked and "moving" by itself.  Then I thought I'd just make the thing move around the screen also.  grin.png


You can get a good look at a steak but shoving your head up a cow's rear end, but wouldn't you rather take the butchers word for it?


Jstjacques
  • Members
  • 112 posts
  • Last active: May 12 2014 09:43 PM
  • Joined: 10 Jan 2013

Updated code in the first post now.  If you try the code, make sure to change the 4 images called out in the GUI to 4 images you have available!


You can get a good look at a steak but shoving your head up a cow's rear end, but wouldn't you rather take the butchers word for it?