version = PKMidle v1.44 #Persistent #SingleInstance force IniRead, Loadlevel, PKMidle.ini, Settings, 1 ;read settings from ini-file IniRead, ConsecMins, PKMidle.ini, Settings, 2 IniRead, IdleMinsTrigger, PKMidle.ini, Settings, 3 IniRead, File1Selected, PKMidle.ini, Settings, 4 IniRead, CloseChecked, PKMidle.ini, Settings, 5 IniRead, Start, PKMidle.ini, Settings, 6 IniRead, Slang, PKMidle.ini, Settings, 7 IniRead, File2Selected, PKMidle.ini, Settings, 8 IniRead, File2Checked, PKMidle.ini, Settings, 9 IniRead, GColor, PKMidle.ini, Settings, 10 loop,60 { t := 10+a_index IniRead, t%t%, PKMidle.ini, %Slang%,%t% ;read language strings } if t70 <> Check ;check for existence / health ini-file { MsgBox, 262144, PKMidle - Error, PKMidle.ini is corrupt or missing: please reinstall`n`nPKMidle.ini is corrupt of ontbreekt: herinstalleer ExitApp } peak := 0 show := 1 tijd := 0 tab := " " scheme := "3 -n" if File1Selected= File1Selected=<---- if File2Selected= File2Selected=<---- File1SelectedRun = 0 File2SelectedRun = 0 GuiColor = d4ebff PBcolor = f8d5b2 if GColor = 0 { GuiColor = fee9d6 PBcolor = bafff9 } if A_OSVersion not in WIN_2003,WIN_XP,WIN_2000,WIN_NT4,WIN_95,WIN_98,WIN_ME ; is OS Windows Vista, 7 or higher? { t25 = %t26% t32 = %t31% scheme := } Menu, tray, add, Info, About ;create a Tray Menu Menu, tray, add, Menu, tray, add, %t42%, Show Menu, tray, add, Menu, tray, add, %t43%, Exit Menu, tray, tip, %Version%`n%t44%`n%t45% Menu, tray, default, %t42% Menu, tray, click, 1 Menu, tray, NoStandard Run, powercfg -change %scheme%,, Hide UseErrorLevel ;set XP power scheme 'Always on' Run, powercfg -setactive %scheme%,, Hide UseErrorLevel Loop,2 { Run, powercfg -change %scheme% /standby-timeout-ac 0,, Hide UseErrorLevel ;disable timer standby and hibernate - XP/Vista/7 Run, powercfg -change %scheme% /standby-timeout-dc 0,, Hide UseErrorLevel Run, powercfg -change %scheme% /hibernate-timeout-ac 0,, Hide UseErrorLevel Run, powercfg -change %scheme% /hibernate-timeout-dc 0,, Hide UseErrorLevel scheme := } Prefs: File1SelectedRun = 0 sethi = CpuCount = -1 cloak = hidden ;hide some lines min = - ;set ypos negative for the hidden lines to shorten the gui hoog = 55 msg := 31+Start, message := t%msg% if Start = 4 { cloak = min = hoog = 124 } Gui, destroy Gui, color, % GuiColor ; bv d4ebff of fee9d6 Gui, add, GroupBox, x10 y6 w200 h60 cblack,%t11% Gui, add, edit, Number center x25 y30 r1 w25 vLoadlevel, %loadlevel% Gui, add, text, x+5 y33, `% Gui, add, text, x67 y33, %t12% Gui, add, edit, Number center x+5 y30 r1 w25 vConsecMins, %ConsecMins% Gui, add, text, x+5 y33, %t13% Gui, add, text, w35 x210 y33 center, %t14% Gui, add, GroupBox, x245 y6 w185 h60 cblack, %t15% Gui, add, edit, Number center w40 x300 y30 r1 w25 vIdleMinsTrigger, %IdleMinsTrigger% Gui, add, text, x+5 y33, %t13% Gui, add, GroupBox, x10 y70 w420 h%hoog% cblack, %t16% Gui, add, Button, w44 h22 x25 y90 gNu, %t17% Gui, add, DropDownList, x+10 w170 choose%Start% AltSubmit vStart gStartKeuze, %t25%|%t27%|%t28%|%t29% Gui, add, text, x260 y87, %t18% Gui, add, text, x260 y100, %t19% Gui, Add, DateTime, vtijdset 1 w55 x+10 y90 gOptijd, HH:mm Gui, add, Checkbox, x+5 y90 vtijd CheckedNo gOptijd, OK Gui, add, Button, x25 y%min%115 %cloak% gSetFile1,... Gui, add, edit, x+1 y%min%116 w275 %cloak% vFile1Selected, %File1Selected% Gui, add, Checkbox, x+6 ys%min%+110 %cloak% vCloseChecked Checked%CloseChecked% gCloseChecked, %t30% Gui, add, Checkbox, x32 ys%min%+135 w15 h15 %cloak% vFile2Checked Checked%file2% gFile2Checked Gui, add, text, x50 y%min%142 %cloak% vFile2Text, %t46% Gui, add, Button, x25 y%min%158 %cloak% vFile2Select gSetFile2,... Gui, add, edit, x+1 y%min%159 w275 %cloak% vFile2Selected, %File2Selected% Gui, font, bold Gui, add, Button, w90 x9 gStopTimer vStopStart Gui, add, text, cGreen w240 x+0 center, %t21% Gui, font Gui, add, Button, w90 x+1 gSave, %t20% Gui, add, Button, w15 h15 x219 y0 gAbout, ? Gui, add, GroupBox, x220 y11 w15 h21 cblack Gui, Add, Progress, x221 y18 w12 h12 Disabled Background%PBcolor% vProgress Gui, Add, Text, xp yp wp hp cFFFFFF BackgroundTrans 0x201 vText gGuiColor,   Gui, add, StatusBar, Backgroundf4f891 -Theme SB_SetParts(120, 168) ;split Status bar if CloseChecked = 1 ;checkbox 'close PKMidle' (after running a file) checked? { Gui, Submit, NoHide Guicontrol, disable, File2Checked ;disable all the controls for File2 Guicontrol, disable, File2Text GuiControl, disable, File2Select GuiControl, disable, File2Selected } if File2Checked = 0 ;checkbox 'Start second file' not checked? { Gui, Submit, NoHide GuiControl, disable, File2Select ;disable file search control GuiControl, disable, File2Selected ;disable control File2Selected } Hotkey, ^!., Nu ;ctrl+alt+. hotkey Gosub, Starttimer Show: if show = 0 { show = 1 Gui, show,, %version% ;show the window WinSet, TopMost, On, %version% OnMessage(0x112, "WM_SYSCOMMAND") ;watch window messages Return } show = 0 Gui, hide ;hide the window Return GuiColor: if GuiColor = fee9d6 { GuiColor = d4ebff PBcolor = f8d5b2 GColor = 1 } else { GuiColor = fee9d6 PBcolor = bafff9 GColor = 0 } show = 0 Goto Prefs CloseChecked: Gui, Submit, NoHide if CloseChecked = 1 ;checkbox 'close PKMidle' (after running a file) checked after clicking the box { Guicontrol, disable, File2Checked ;disable the controls for File2 Guicontrol, disable, File2Text GuiControl, disable, File2Select GuiControl, disable, File2Selected } else { Guicontrol, enable, File2Checked ;enable them again when checkbox is off Guicontrol, enable, File2Text if File2Checked = 1 ;checkbox 'Start second file' checked? { GuiControl, enable, File2Select GuiControl, enable, File2Selected } } Return SetFile1: ;choose file to execute after set conditions FileSelectFile, File1Selected, 3,, %t36% if File1Selected = MsgBox, 262144, %t37%, %t38% else GuiControl,, File1Selected, %File1Selected% Return File2Checked: ;is checkbox (for starting a second file) checked? Gui, Submit, NoHide if File2Checked = 1 { GuiControl, enable, File2Select ;enable control File2Select GuiControl, enable, File2Selected ;enable control File2Selected } else { GuiControl, disable, File2Select ;disable control File2Select GuiControl, disable, File2Selected ;disable control File2Selected } Return SetFile2: ;choose file to execute after keyboard or mouse activity FileSelectFile, File2Selected, 3,, %t36% if File2Selected = MsgBox, 262144, %t37%, %t38% else GuiControl,, File2Selected, %File2Selected% Return StartKeuze: Gui, submit show = 0 Goto Prefs CheckCpuLoad: Gui, Submit, NoHide SetFormat, Float, 0.0 CpuLoad := GetCpuLoad() ;get value of CPU function if CpuLoad > %Loadlevel% { peak++ if peak > 3 ;CPUload higher for more than 3 seconds (suppress short peaks) { peak := 0 CpuCount = -1 ;reset the CpuCount } } else { peak := 0 ;CPUload less than 3 seconds higher: reset the peak counter } CpuCount := CpuCount+1 ;else add 1 to the CpuCount if CpuLoad < 1 CpuLoad = 0 if Loadlevel = 0 ;no trigger if the set cpu-level = 0 CpuCount = 0 ConsecSeconds := ConsecMins*60, IdleSecondsTrigger := IdleMinsTrigger*60 ActualSecsIdle := (A_TimeIdle / 1000)*(!tijd) SB_SetText(" " t22 " " . CpuLoad " % ", 1) ;update the StatusBar SB_SetText(" " t23 " " CpuCount//60 " m " Mod(CpuCount,60) " s ", 2) if File1SelectedRun = 1 SB_SetText(" " t23 " - - - - - -", 2) SB_SetText(" " t24 " " ActualSecsIdle//60 " m " Mod(ActualSecsIdle, 60) " s", 3) OnMessage(0x200,"Hover") ;0x200 = WM_MOUSEMOVE used instead of WM_MOUSEHOVER 0x2A1 if (File1SelectedRun = 1) and (File2Checked = 1) ;run a program after keyboard/mouse activity if ActualSecsIdle < 1 { if FileExist(File2Selected) ;existing file? { Run, %File2Selected%,, UseErrorLevel ;start a file/program File2SelectedRun = 1 } else { MsgBox, 262144,PKMidle - %t35%, %t41% ;file does not exist } File1SelectedRun = 0 } Optijd: if tijd = 1 { CpuCount = -1 GuiControlGet tijdset tijdnu = %A_Hour%%A_Min%%A_Sec% StringMid, tijdset, tijdset, 9, 4 tijdset = %tijdset%00 if (tijdnu = tijdset) { CpuCount = 30000 ActualSecsIdle = 30000 GuiControl,, tijd, 0 } } if (ActualSecsIdle > 2) and (sethi = "") { if Start = 1 ;hibernate selected? { sethi = 1 Run, powercfg -h on,, Hide UseErrorLevel ;switch Hibernate mode on } else { sethi = 0 Run, powercfg -h off,, Hide UseErrorLevel ;switch Hibernate mode off } } ifGreater, CpuCount, %ConsecSeconds% , ifGreater, ActualSecsIdle, %IdleSecondsTrigger% { if File1SelectedRun = 0 { Nu: MsgBox, 262404, PKMidle - %t39%, %tab%%message%`n`n %t40%, 5 ;5-second timeout before execution ifMsgBox, No Return if Start = 1 DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0) ;put pc into Hibernation if Start = 2 DllCall("PowrProf\SetSuspendState", "int", 0, "int", 1, "int", 0) ;put pc into Standby if Start = 3 Shutdown, 12 ;switch pc off (forced) if Start = 4 { if FileExist(File1Selected) ;existing file? { Run, %File1Selected%,, UseErrorLevel ;start a file/program File1SelectedRun = 1 if CloseChecked = 1 ;exit after starting program ExitApp } else { MsgBox, 262144, PKMidle - %t35%, %t41% ;file does not exist } } CpuCount := 0 Return } CpuCount := 0 Return } Return GetCpuLoad() { Static oldIdleTime, oldKrnlTime, oldUserTime Static newIdleTime, newKrnlTime, newUserTime oldIdleTime := newIdleTime oldKrnlTime := newKrnlTime oldUserTime := newUserTime DllCall("GetSystemTimes", "int64P", newIdleTime, "int64P", newKrnlTime, "int64P", newUserTime) Return (1 - (newIdleTime-oldIdleTime)/(newKrnlTime-oldKrnlTime + newUserTime-oldUserTime)) * 100 -1 } StopTimer: if stop = 0 { stop = 1 SetTimer, CheckCpuLoad, off Menu, tray, icon, PKMidle.exe, 2 GuiControl,, StopStart, %t47% Return } Starttimer: stop = 0 SetTimer, CheckCpuLoad, 1000 CpuCount = 0 Menu, tray, icon,* GuiControl,, StopStart, %t48% Return Save: Gui, Submit IniWrite, %Loadlevel%, PKMidle.ini, Settings, 1 ;write values to disk IniWrite, %ConsecMins%, PKMidle.ini, Settings, 2 IniWrite, %IdleMinsTrigger%, PKMidle.ini, Settings, 3 IniWrite, %File1Selected%, PKMidle.ini, Settings, 4 IniWrite, %CloseChecked%, PKMidle.ini, Settings, 5 IniWrite, %Start%, PKMidle.ini, Settings, 6 IniWrite, %Slang%, PKMidle.ini, Settings, 7 IniWrite, %File2Selected%, PKMidle.ini, Settings, 8 IniWrite, %File2Checked%, PKMidle.ini, Settings, 9 IniWrite, %GColor%, PKMidle.ini, Settings, 10 Reload ;reload script and values Return About: Gui,9:color, % GuiColor Gui,9:-Sysmenu Gui,9:Font, Bold Gui,9:Add, GroupBox,x6 y15 w380 r9.3 cblack, %Version% Gui,9:Font Gui,9:Add, DropDownList, x20 y35 w100 choose%Slang% AltSubmit vSlang gSave, Nederlands|English|Translation Gui,9:Add, Text, x20 y60, %t50% loop, 9 { msg := 50+a_index, txt := t%msg% Gui,9:Add, Text, y+1, %txt% } Gui,9:Font, CBlue underline Gui,9:Add, Text, x+3 gHomepage, %t60% Gui,9:Font Gui,9:Add, Text, x+3, %t61% Gui,9:Add, Text, x20 y+35, %t62% Gui,9:Font, CBlue underline Gui,9:Add, Text, x+3 gDonationCoder, www.DonationCoder.com Gui,9:Font Gui,9:Font, Bold Gui,9:Add, Text,x20 y+5, AutoHotkey Gui,9:Font Gui,9:Add, Text, y+3, %t63% Gui,9:Font, CBlue underline Gui,9:Add, Text, x+3 gAutoHotkey, www.AutoHotkey.com Gui,9:Font Gui,9:Font, Bold Gui,9:Add, Text, x20 y+8, GvB 2009 - 2020 Gui,9:Font Gui,9:Add, Text, x+15, %t64% Gui,9:Font, Bold Gui,9:Add, GroupBox, x6 yp-72 w380 r4 cblack, DonationCoder Gui,9:Add, Button, xm+150 gAboutOK Default w75, &OK Gui,9:Show,, %t65% WinSet, TopMost, On, %t65% Return WM_SYSCOMMAND(wParam) ;disable close button { if (A_Gui = 1 && wParam = 0xF060) ;SC_CLOSE { global show := 0 Gui, hide return 0 } } AboutOK: Gui, 9:Destroy Return DonationCoder: Run, http://www.donationcoder.com,, UseErrorLevel Return AutoHotkey: Run, http://www.autohotkey.com,, UseErrorLevel Return Homepage: Run, https://gvanberk.home.xs4all.nl/Download.html,, UseErrorLevel Return Hover() { if A_GuiControl = StopStart ;mouse cursor hovers over StopStart control SetTimer, ShowTT, 500 else { SetTimer, ShowTT, off ToolTip ;erase } Return } ShowTT: GuiControlGet StopStart ;retrieve the text on the button and display the right tooltip if StopStart = %t48% ToolTip, %t66%`n%t67%`n%t68% else ToolTip, %t69% Return Exit: GuiClose: ExitApp