local secondsBetweenActions = 2*60; local avoidInterupts = true; -- Whether or not to try and avoid input while the user has recently been controlling the game local timeLeft; local win; local targetWindowClass = "ArcheAge"; local targetWindowName = "- ArcheAge*- *"; function searchForWindow() win = window.find(targetWindowName, targetWindowClass); if( win ) then printf("ArcheAge window found: 0x%X\n", win); printf("You can now walk away from the computer!\n"); timeLeft = 3; end end function macro.init() timeLeft = 0; win = window.find(targetWindowName, targetWindowClass); searchForWindow(); if( not win ) then printf("You need to have ArcheAge running. Start it, focus the window, and press the END key on your keyboard.\n"); end end function macro.main(dt) timeLeft = timeLeft - dt; if( win and timeLeft < 0 ) then if( window.valid(win) ) then timeLeft = secondsBetweenActions; printf("Preventing idle in Arche Age\t%s\n", os.date("%I:%M %p")); keyboard.virtualPress(win, key.VK_END); else printf("\a\aArcheAge window lost... Waiting for a new window.\t(%s)\n", os.date("%I:%M %p")); win = nil; searchForWindow(); timeLeft = 60; end elseif( timeLeft < 0 ) then timeLeft = 60; searchForWindow(); end return true; end function macro.event(e, data1, data2, data3) if( e == "keypressed" ) then if( data1 == key.VK_END ) then local newWin = window.getFocusHwnd(); local newClass = window.getClassName(newWin); if( newClass == targetWindowClass ) then printf("ArcheAge target window has been changed: 0x%X.\n", newWin); win = window.getFocusHwnd(); timeLeft = 3; end end end -- User actually sent input, so we can delay anti-idle if( avoidInterupts and (e == "keypressed" or e == "mousepressed") and window.getFocusHwnd() == win ) then timeLeft = secondsBetweenActions; end end