Leaderboard
Popular Content
Showing content with the highest reputation on 08/15/2018 in all areas
-
ImageSearch multiple occurrence
yutijang reacted to PoojaKrishna for a topic
I have developed a script to find multiple or all occurrence of an image from desktop using the ImageSearch UDF. Please note that the resulting array has the starting position of the images, not middle. #include-once #include <Array.Au3> #RequireAdmin #AutoIt3Wrapper_UseX64=Y Global $y = 0, $x = 0 ;Result x and y coordinates Dim $aResult[1] ;Resulting array Global $sImagePath = @ScriptDir &"\Rect.bmp" Global $nImageWidth = 0 ;Image width Global $nImageHeight = 0 ;Image Height _ImageSearchMultiple() Func _ImageSearchMultiple() Local $search = _ImageSearch($sImagePath, 0, $x, $y, 10) If $search = 1 Then _ArrayDisplay($aResult) Else Msgbox(0,"Not Found","Image Not Found") EndIf EndFunc ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with Image Search ; Require that the ImageSearchDLL.dll be loadable ; ; ------------------------------------------------------------------------------ ;=============================================================================== ; ; Description: Find the position of an image on the desktop ; Syntax: _ImageSearchArea, _ImageSearch ; Parameter(s): ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify ; a desktop region to search ; ;=============================================================================== Func _ImageSearch($findImage,$resultPosition, ByRef $x, ByRef $y,$tolerance, $HBMP=0) $nStartX = 0 $nStartY = 0 $nMaxX = @DesktopWidth $nMaxY = @DesktopHeight $nEndX = $nMaxX $nEndY = $nMaxY $nCount = 0 $aResult[0] = $nCount ; Count $nImageWidth = 0 $nImageHeight = 0 While (1) $nResult = _ImageSearchArea($findImage,$resultPosition,$nStartx,$nStarty,$nEndX,$nEndY,$x,$y,$tolerance,$HBMP) If $nResult = 1 Then $nCount = $nCount + 1 $aResult[0] = $nCount Redim $aResult[$nCount + 1 ] $aResult[$nCount] = $x & "," & $y $nStartX = $x + $nImageWidth $nStartY = $y $nEndX = $nMaxX $nEndY = $y + $nImageHeight If $nStartX + $nImageWidth > $nMaxX Or $nStartY + $nImageHeight > $nMaxY Then $nStartX = 0 $nStartY = $y + 1 $nEndX = $nMaxX $nEndY = $nMaxY ContinueLoop EndIf Else If $nEndY >= $nMaxY Then ExitLoop Else $nStartX = 0 $nStartY = $Y + 1 $nEndX = $nMaxX $nEndY = $nMaxY EndIf EndIf wend If $aResult[0] = 0 Then Return 0 Else Return 1 EndIf EndFunc Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom, ByRef $x, ByRef $y, $tolerance,$HBMP=0) ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage If IsString($findImage) Then $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP) Else $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP) EndIf If IsArray( $result ) = 0 Then return 0 ; If error exit if $result[0]="0" then return 0 ; Otherwise get the x,y location of the match and the size of the image to ; compute the centre of search $array = StringSplit($result[0],"|") $x=Int(Number($array[2])) $y=Int(Number($array[3])) If $nImageWidth = 0 Then $nImageWidth = Int(Number($array[4])) $nImageHeight = Int(Number($array[5])) EndIf if $resultPosition=1 then $x=$x + Int(Number($array[4])/2) $y=$y + Int(Number($array[5])/2) endif return 1 EndFunc ;=============================================================================== ; ; Description: Wait for a specified number of seconds for an image to appear ; ; Syntax: _WaitForImageSearch, _WaitForImagesSearch ; Parameter(s): ; $waitSecs - seconds to try and find the image ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; ;=============================================================================== Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition, ByRef $x, ByRef $y,$tolerance,$HBMP=0) $waitSecs = $waitSecs * 1000 $startTime=TimerInit() While TimerDiff($startTime) < $waitSecs sleep(100) $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance,$HBMP) if $result > 0 Then return 1 EndIf WEnd return 0 EndFunc ;=============================================================================== ; ; Description: Wait for a specified number of seconds for any of a set of ; images to appear ; ; Syntax: _WaitForImagesSearch ; Parameter(s): ; $waitSecs - seconds to try and find the image ; $findImage - the ARRAY of images to locate on the desktop ; - ARRAY[0] is set to the number of images to loop through ; ARRAY[1] is the first image ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns the index of the successful find ; On Failure - Returns 0 ; ; ;=============================================================================== Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition, ByRef $x, ByRef $y,$tolerance,$HBMP=0) $waitSecs = $waitSecs * 1000 $startTime=TimerInit() While TimerDiff($startTime) < $waitSecs for $i = 1 to $findImage[0] sleep(100) $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance,$HBMP) if $result > 0 Then return $i EndIf Next WEnd return 0 EndFunc Func _ImageSize($sFileName) Local $aRet[2], $sExt = StringRegExpReplace($sFileName, "^.*\.", "") If (FileExists($sFileName) = 0) Or _ ((StringLen($sExt) = 3) And (StringRegExp($sExt, "(?i)(bmp|gif|jpg|png|tif|emf|wmf)") = 0)) Or _ ((StringLen($sExt) = 4) And (StringRegExp($sExt, "(?i)(tiff|jpeg)") = 0)) Then _ Return SetError(1, 0, $aRet) Local $ghGDIPDll = DllOpen("GDIPlus.dll") Local $tInput = DllStructCreate("int Version;ptr Callback;int NoThread;int NoCodecs") Local $tToken = DllStructCreate("ulong_ptr Data") DllStructSetData($tInput, "Version", 1) DllCall($ghGDIPDll, "int", "GdiplusStartup", "ptr", DllStructGetPtr($tToken), "ptr", DllStructGetPtr($tInput), "ptr", 0) Local $aImage = DllCall($ghGDIPDll, "int", "GdipLoadImageFromFile", "wstr", $sFileName, "ptr*", 0) Local $aResult = DllCall($ghGDIPDll, "int", "GdipGetImageWidth", "handle", $aImage[2], "uint*", -1) $aRet[0] = $aResult[2] $aResult = DllCall($ghGDIPDll, "int", "GdipGetImageHeight", "handle", $aImage[2], "uint*", 0) $aRet[1] = $aResult[2] DllCall($ghGDIPDll, "int", "GdipDisposeImage", "handle", $aImage[2]) DllCall($ghGDIPDll, "none", "GdiplusShutdown", "ptr", DllStructGetData($tToken, "Data")) DllClose($ghGDIPDll) Return SetError(0, 0, $aRet) EndFunc ;==>_ImageSize I'm also attaching the code to capture the image , written by Melba23. #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #Include <ScreenCapture.au3> #Include <Misc.au3> #include <WinAPISysWin.au3> #include <File.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #Include <ScreenCapture.au3> #Include <Misc.au3> #include <WinAPISysWin.au3> Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path Mark_Rect() Func Mark_Rect() Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp Local $UserDLL = DllOpen("user32.dll") ; Create transparent GUI with Cross cursor $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST) WinSetTrans($hCross_GUI, "", 8) GUISetState(@SW_SHOW, $hCross_GUI) GUISetCursor(3, 1, $hCross_GUI) Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0x000000) ; Wait until mouse button pressed While Not _IsPressed("01", $UserDLL) Sleep(10) WEnd ; Get first mouse position $aMouse_Pos = MouseGetPos() $iX1 = $aMouse_Pos[0] $iY1 = $aMouse_Pos[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $UserDLL) $aMouse_Pos = MouseGetPos() $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0) $hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1) ; Bottom of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1]) ; Right of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) ; Set overall region _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask) If WinGetState($hRectangle_GUI) < 15 Then GUISetState() Sleep(10) WEnd ; Get second mouse position $iX2 = $aMouse_Pos[0] $iY2 = $aMouse_Pos[1] ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf GUIDelete($hRectangle_GUI) GUIDelete($hCross_GUI) DllClose($UserDLL) $sBMP_Path = @ScriptDir & "\Rect.bmp" _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False) EndFunc ;==>Mark_Rect Please see the following links to see the original posts on the ImageSearch UDF and the usage. I hope it will help someone here.1 point -
Why would you upload this without including source code?1 point
-
Install software using chocolatey
Earthshine reacted to legend for a topic
#RequireAdmin #include <File.au3> ;------------------------------------------------------------------------------------------------------------------------------------------- install("winrar",True) ;------------------------------------------------------------------------------------------------------------------------------------------- ;Installs chocolatey. $choco1 = "@powershell -NoProfile -ExecutionPolicy unrestricted -Command" $choco2 = " (iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" $choco3 = " && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" if not FileExists(@AppDataCommonDir & "\Chocolatey\") then RunWait(@ComSpec & " /C " & $choco1 & $choco2 & $choco3, "", @SW_HIDE) $find = '"' & "allowGlobalConfirmation" & '"' & " enabled=" & '"' & "false" & '"' & " setExplicitly=" & '"' & "false" & '"' $replace = '"' & "allowGlobalConfirmation" & '"' & " enabled=" & '"' & "true" & '"' & " setExplicitly=" & '"' & "true" & '"' _ReplaceStringInFile(@AppDataCommonDir & "\Chocolatey\config\chocolatey.config", $find, $replace) EndIf ;------------------------------------------------------------------------------------------------------------------------------------------- ;Install and uninstall functions Func install($package_name,$notify) RunWait(@ComSpec & " /C " & "choco install " & $package_name, "", @SW_HIDE) if $notify = True Then MsgBox(64,"Installed", $package_name & " has been installed.") EndFunc Func uninstall($package_name, $notify) RunWait(@ComSpec & " /C " & "choco uninstall " & $package_name, "", @SW_HIDE) if $notify = True Then MsgBox(64,"Uninstalled", $package_name & " has been uninstalled.") EndFunc ;------------------------------------------------------------------------------------------------------------------------------------------- a small script i made to install software using chocolatey: https://chocolatey.org/ If chocolatey isn't installed, it will install it, and afterwards install the package you defined. All packages can be found here: https://chocolatey.org/packages1 point -
I appreciate the help, however in my inexperienced view it seems you are doing nearly the same thing as me except that your method of connecting the stringsplit pieces togetther causes a 90 rotation of the data which you then correct with another function. I did limited testing, but have found that when converting 128,417 characters on 8160 lines in a .csv file your code takes ~0.4 seconds longer at ~36.5 seconds which is the best speed difference. This file size is at the smaller end of potential files with mid size files being 1-4 MB which can take multiple hours so your 1% slower, while probably much better written is too much of a cost. Still thank you for your time and effort. I hope this scenario was a good test of your code. With that said, I'm looking for anything that can beet ~36.1 seconds with this file below. If you think you know how to do it feel free to test it yourself or send it to me. tmp4.csv1 point
-
Great job! Added the UDF to the wiki: https://www.autoitscript.com/wiki/User_Defined_Functions#Controls1 point
-
Thanks for this awesome tool, and an example of advanced AutoIt usage. btw. I think you should update your signature1 point
-
Working ImageSearch - (Moved)
TurionAltec reacted to autocart for a topic
Hi Atoxis, I kind of "wrapped" the ImageSearch command from ... *cough* ... cannot say it out loud in here ... (*whispering*) AutoHotKey ... to an AutoIt function. Of course a separate dll must be downloaded from here: https://hotkeyit.github.io/v2/ Either one of the dll packages (v1 or v2) should do the trick. Just don't use the help file of v1. It's confusing and misleading. Even the author says on that page that it is outdated. Don't know why it is still packaged with the v1 zip package. So make sure to at least download v2 for the help file. And, if you want it, v1 for the possibly more stable version? If you should be using the 32-bit v1 version after all, make sure to be using the "w" version, not the "a". I am not an expert with dll calls. So the code underneath is the result of trial and error based on reading the help files rather than of always exactly knowing what must be coded. I also did not do much error catching in the code - or none at all - but the code is not so complicated nor long. It also might not be the fastest ImageSearch-code out there, but hey, the code works for me (on Win 8.1 x64 and with both 32-bit and 64-bit AutoIt) and I think it is fairly simple to implement. But I am willing to work on improving the code upon feedback. (The additional plus of this code is that you can practically wrap any ahk command or fuction to AutoIt by copying and slightly adapting the code. Not that there would be much need for that but who knows, maybe tomorrow one of us stumbles upon another case like ImageSearch.) Hope it helps either you, Atoxis, or someone else in the future. Regards, S. $searchAreaX1 = xxxxx ;//upper left X value of search area $searchAreaY1 = yyyyy ;//upper left Y value of search area $searchAreaX2 = xxxxxx ;//lower right X value of search area $searchAreaY2 = yyyyyy ;//lower right Y value of search area $OptionsAndImageFile = "..." ;//e.g. "*20 *TransBlack (relative) path to image.png", see https://www.autohotkey.com/docs/commands/ImageSearch.htm ;~ $ImageSearchCoordMode = "..." ;//Specify whether all coordinates are relative to "Screen|Window|Client". Can be skipped. Default is "Window" (meaning the one active while the ImageSearch function runs). see also https://www.autohotkey.com/docs/commands/CoordMode.htm WinActivate(".......", "") ;//if coordinates are relative to window, it makes sense to activate the desired window before performing the search WinWaitActive("[LAST]") $imageFoundAt = ImageSearch_ahk_wrapped($searchAreaX1, $searchAreaY1, $searchAreaX2, $searchAreaY2, $OptionsAndImageFile) If $imageFoundAt[0] Then MsgBox(0, "ImageSearch results", "Image found at the coordinates: X " & $imageFoundAt[0] & ", Y " & $imageFoundAt[1]) Else MsgBox(0, "ImageSearch results", "Image not found.") EndIf ;// VVV BEGINNING OF "WRAPPER"-FUNCTION: VVV Func ImageSearch_ahk_wrapped($searchAreaX1, $searchAreaY1, $searchAreaX2, $searchAreaY2, $OptionsAndImageFile, $ImageSearchCoordMode = "Window") ;// >>> IN THE NEXT 4 LINES OF CODE CHOOSE THE DLL OF YOUR CHOICE SO THAT IT FITS THE BIT-VERSION OF YOUR DESIRED AUTOIT.EXE BY COMMENTING THE OTHER LINES OUT. THIS WAY THE CODE CAN BE REUSED/REVISITED AND QUICKLY ADAPTED. ;// >>> IN THE NEXT 6 LINES OF CODE ADAPT THE PATHS/STRINGS TO YOUR LOCAL CIRCUMSTANCES. ;~ $path_to_AutoHotkey_dll = ".\ahkdll-v1-release-master\Win32w\AutoHotkey.dll" ;~ $path_to_AutoHotkey_dll = ".\ahkdll-v1-release-master\x64w\AutoHotkey.dll" ;~ $path_to_AutoHotkey_dll = ".\ahkdll-v2-release-master\Win32w\AutoHotkey.dll" $path_to_AutoHotkey_dll = ".\ahkdll-v2-release-master\x64w\AutoHotkey.dll" $part_of_path_identifying_version1 = "ahkdll-v1-release-master" $part_of_path_identifying_version2 = "ahkdll-v2-release-master" $hDll = DllOpen($path_to_AutoHotkey_dll) DllCall($hDll, "UINT_PTR:cdecl", "ahkdll", "wstr", "", "wstr", "", "wstr", "") If StringInStr($path_to_AutoHotkey_dll, $part_of_path_identifying_version1) Then DllCall($hDll, "BOOLEAN:cdecl", "ahkExec", "wstr", "CoordMode Pixel, " & $ImageSearchCoordMode) DllCall($hDll, "BOOLEAN:cdecl", "ahkExec", "wstr", "ImageSearch foundX, foundY, " & $searchAreaX1 & ", " & $searchAreaY1 & ", " & $searchAreaX2 & ", " & $searchAreaY2 & ", " & $OptionsAndImageFile) ElseIf StringInStr($path_to_AutoHotkey_dll, $part_of_path_identifying_version2) Then DllCall($hDll, "BOOLEAN:cdecl", "ahkExec", "wstr", "CoordMode ""Pixel"", """ & $ImageSearchCoordMode & """") DllCall($hDll, "BOOLEAN:cdecl", "ahkExec", "wstr", "ImageSearch foundX, foundY, " & $searchAreaX1 & ", " & $searchAreaY1 & ", " & $searchAreaX2 & ", " & $searchAreaY2 & ", """ & $OptionsAndImageFile & """") EndIf $foundX = DllCall($hDll, "wstr:cdecl", "ahkgetvar", "wstr", "foundX", "UInt", 0) $foundY = DllCall($hDll, "wstr:cdecl", "ahkgetvar", "wstr", "foundY", "UInt", 0) Local $returnArray[2] $returnArray[0] = $foundX[0] $returnArray[1] = $foundY[0] DllClose($hDll) Return $returnArray EndFunc1 point -
Screensaver, Sleep, Workstation Lock, and Power-Save Disabling Since I see this question asked again and again, and the simple answer isn't always given (or at least, only half of it is), I'm posting this for reference. To disable Power-saving, Workstation Locking, Screensavers, etc., all that's needed is a call to SetThreadExecutionState. No need for timers, nor for emulating mouse or keyboard input. Just make a call to that API once to disable any locking/sleeping/screensaverin'. When you're done, make another call to it with the proper parameters (this part is important), and everything will be restored. NOTE: The 'execution state' should really only matter while the program that made the call is running (its supposed to be per-application). Once it is terminated, the execution state should be restored. However, there have been some unusual reports regarding this, especially when it is called by more than one process. The main functions in my module are _PowerKeepAlive() and _PowerResetState(). One keeps everything 'awake', the other reenables the default state of Windows power settings (including screensavers and workstation locking). The primary reason I've used this myself is for games that forget to call that API function, and after playing with the joystick for a while, a screensaver or lock-screen will pop up. Using these functions will workaround that problem. Also!: If you want to save and restore the current power-savings 'execution state', just pass the return value from _PowerKeepAlive() as the first argument to 'SetThreadExecutionState'. Anyway, here's the main module I use (example use is below): #include-once ; =============================================================================================================================== ; <_PowerKeepAlive.au3> ; ; Functions to prevent/disable sleep/power-savings modes (AND screensaver) ; ; Functions: ; _PowerKeepAlive() ; _PowerResetState() ; ; See also: ; <_ScreenSaverFunctions.au3> ; query, change, enable & disable screensaver. ; ; Author: Ascend4nt ; =============================================================================================================================== ; ========================================================================================================================== ; Func _PowerKeepAlive() ; ; Function to Prevent the Screensaver and Sleep/Power-savings modes from kicking in. ; NOTE: Be sure to reset this state on exit! ; ; Returns: ; Success: @error=0 & previous state as # (typically 0x80000000 [-2147483648]) ; Failure: @error set (returns 0x80000000, but thats just the normal state) ; @error = 2 = DLLCall error. @extended = DLLCall error code (see AutoIt Help) ; ; Author: Ascend4nt ; ========================================================================================================================== Func _PowerKeepAlive() #cs ; Flags: ; ES_SYSTEM_REQUIRED (0x01) -> Resets system Idle timer ; ES_DISPLAY_REQUIRED (0x02) -> Resets display Idle timer ; ES_CONTINUOUS (0x80000000) -> Forces 'continuous mode' -> the above 2 will not need to continuously be reset #ce Local $aRet=DllCall('kernel32.dll','long','SetThreadExecutionState','long',0x80000003) If @error Then Return SetError(2,@error,0x80000000) Return $aRet[0] ; Previous state (typically 0x80000000 [-2147483648]) EndFunc ; ========================================================================================================================== ; Func _PowerResetState() ; ; Function to Reset the Screensaver and Sleep/Power-savings modes to defaults. ; NOTE: The timer is reset on each call to this! ; ; Returns: ; Success: @error=0 & previous state as # ; Failure: @error set (returns 0x80000000, but thats just the normal state) ; @error = 2 = DLLCall error. @extended = DLLCall error code (see AutoIt Help) ; ; Author: Ascend4nt ; ========================================================================================================================== Func _PowerResetState() ; Flag: ES_CONTINUOUS (0x80000000) -> (default) -> used alone, it resets timers & allows regular sleep/power-savings mode Local $aRet=DllCall('kernel32.dll','long','SetThreadExecutionState','long',0x80000000) If @error Then Return SetError(2,@error,0x80000000) Return $aRet[0] ; Previous state EndFunc Example usage: #NoTrayIcon #include "_PowerKeepAlive.au3" ; Singleton code: If WinExists("SA_0bc53fe0-59c2-11e2-bcfd-0800200c9a66_SA") Then Exit AutoItWinSetTitle("SA_0bc53fe0-59c2-11e2-bcfd-0800200c9a66_SA") Opt("TrayOnEventMode", 0) Opt("TrayMenuMode", 1+2) TraySetClick(8+1) Local $iTrayExit = TrayCreateItem("Exit + Reenable Sleep") ; Disable screensaver, power-save, etc _PowerKeepAlive() ; Be sure to register this to reenable power-saving, screensaver, etc OnAutoItExitRegister("_PowerResetState") ; Now we're ready to accept messages TraySetState() While TrayGetMsg() <> $iTrayExit ; No need for sleep WEnd _PowerKeepAlive.au31 point
-
I have a UDF for a progressbar and gui that you should be able to easily modify. See the link in my signature.1 point