Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/04/2017 in all areas

  1. Hello, Im a new AutoIt user, im from Spain and i would like to share here my own image search detection method. What's about it? It's not perfect, but with it you don't need to use any DLL file. You don't need to distribute the image file with your final AU3 Script, or Exe if compiled. The image size does not affect to the detection speed. It's bug free (i believe). You can find here as an attach file, a distro package with all you need, and it includes a simple how-to guide. Im going to paste here the how-to guide: How to use this AutoIt image detector: Point 1: Install JRE (Java Runtime Environment), without this you can't execute Java Applications (.jar files). Open the Java tool named AISD with double click on it, or "java -jar aisd.jar" in the cmd. In AISD, open the image you want to detect in your script. Remember: the upper left pixel of the image, MUST be a not common color in the background if you want a fast detection. Then you will get a script file if you want, or only a clipboard copied version, full ready to paste into your main script because this one comes with extra help codes. Anyway, the generated code is the $sign definition of the image (calm down, point 3 explains what is the $sign and it's easy). Point 2: Paste the mentioned code in your main script, and try to follow the sample_usage script. If you know how to write au3 codes, it should be very easy. In general terms, all you need is to include image_search.au3, and then you can use the func image_search($sign, $width, $height). You need also the get_image_sign() function, that calculates the first parameter for image_search(). The get_image_sign() function is the one you have generated at point 1. Point 3: image_search() returns the center point of the target image. The func needs the $sign from the image, width and height. This $sign is the "footprint" of the image, in the form of an array of 9 integers. In most of the cases the $sign should be enough to identify the image, this is useful because using the $sign instead of the real image let you get a small script and a fast detection. You can also delete the image once you get the $sign. This $sign has always the same size (those 9 integers, it does not matter if the original image is small or big). How can you define the $sign for a certain image?, you don't need to generate the $sign, AISD does (point 1). Follow the sample_usage script and you will get it. Files in this distro package: * AISD.jar: The already explained Java app. * image_search.au3: The library or module with the resources that lets you detect images. * sample_usage.au3: The mentioned sample_usage script. It contains the smallest example, but i think it should be ok for learning purposes. * sample_usage.exe: The sample_usage.au3 script compiled (au3 -> .exe). You can execute this to see the image_search() func working. * sample_target.png: The image to be detected in the sample_usage. You can delete this file and the script will be fine. * OffsetCalc.jar: It's only a Java tool to calculate the offset to transform an XY point into another one. It's useful if you want to use apply_offset function (from image_search.au3). Both things are only necessary when it's hard to find a version of the target image with upper left pixel in the way mentioned. As you can imagine, the idea is to detect another image and then apply the offset to get the real coordinates of the original target image. Happy Detections Lasker image_search.zip
    1 point
  2. [NEW VERSION] - 4 Jun 17 Added: _Notify_Locate now takes an optional second parameter which, when used in a multiple monitor setup, will force the notifications to appear on a specified monitor rather than the left and right side of the entire display area. New UDF in the first post. M23
    1 point
  3. Safearrays can be handled in more or less smarter ways. The smart way is demonstrated in Accessing AutoIt Variables. The required code is contained in the zip below. Now the code in post 276 looks like this: ;#AutoIt3Wrapper_UseX64=y #include "CLR.au3" #include "AccVarsUtilities.au3" Example() Func Example() Local $oAssembly = _CLR_LoadLibrary("System") ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF) Local $pAssemblyType = 0 $oAssembly.GetType_2("System.Diagnostics.Process", $pAssemblyType) ConsoleWrite("$pAssemblyType = " & Ptr($pAssemblyType) & @CRLF) Local $oAssemblyType = ObjCreateInterface($pAssemblyType, $sIID_IType, $sTag_IType) ConsoleWrite("IsObj( $oAssemblyType ) = " & IsObj($oAssemblyType) & @CRLF) Local $sName = "" $oAssemblyType.get_FullName($sName) ConsoleWrite($sName & @CRLF) Local $strProcName[] = ["Notepad"], $pSafeArray AccVars_ArrayToSafeArray( $strProcName, $pSafeArray ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $pObject = 0, $aObject, $oProcess ; Run two Notepad instances $oAssemblyType.InvokeMember_3("Start", 0x158, 0, 0, $pSafeArray, $pObject) $oAssemblyType.InvokeMember_3("Start", 0x158, 0, 0, $pSafeArray, $pObject) Sleep(1000) $oAssemblyType.InvokeMember_3("GetProcessesByName", 0x158, 0, 0, $pSafeArray, $pObject) ConsoleWrite("$pObject: " & IsObj($pObject) & @TAB & "$pObject: " & Ptr($pObject) & @CRLF & @CRLF) AccVars_SafeArrayToArray( $pObject, $aObject ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< For $i = 0 To UBound( $aObject ) - 1 $oProcess = ObjCreateInterface($aObject[$i],"",Default,False) ConsoleWrite("IsObj( $oProcess ) = " & IsObj($oProcess) & @CRLF) ConsoleWrite("-Process " & $i+1 & " Information" & @CRLF) ConsoleWrite("$oProcess.ProcessName : " & $oProcess.ProcessName & @CRLF) ConsoleWrite("$oProcess.Id : " & $oProcess.Id & @CRLF) ConsoleWrite("$oProcess.MainWindowTitle : " & $oProcess.MainWindowTitle & @CRLF) ConsoleWrite(@CRLF) Next EndFunc The code in Accessing AutoIt Variables exploits conversions in internal AutoIt code that takes place between native AutoIt arrays and safearrays in relation to COM objects. The following variant types are directly supported by those conversions: VT_I2, VT_I4, VT_R4, VT_R8, VT_BSTR, VT_BOOL, VT_UI4, VT_UI8 and VT_VARIANT. But VT_UNKNOWN which is used in post 276 is not supported. I've added code to support this type. In AutoIt there is no easy way to deal with safearrays. You can either do something like this, or you can access the variant and safearray data structures directly. The classes in System.Collections namespace is not a workaround. I've only tested the code in post 276. Let me know if there are any issues. AccessingVariables.7z
    1 point
  4. Anantapolk, Welcome to the AutoIt forum. Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked. In future, when you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. See you soon with a legitimate question I hope. M23 P.S. You might find the Recursion tutorial in the Wiki a useful read.
    1 point
  5. GeneNight, Providing a screenshot or a URL so we can see what you are trying to automate might be useful. Believe me, I am quite prepared to accept a reasonable explanation, but as you can see from the earlier posts, I am not alone in finding this question a little odd as it stands. M23
    1 point
  6. Celeri

    AutoIT Speed Tester

    Well maybe it's me (it surely is) but I like my AutoIT code when it's FAST. So here's a little program I whipped up in about an hour. AutoIT_Speed.au3 Updated 19Aug2007 with more comments and more test results It will execute commands of your choice through two loops, 20 packs of 9999 iterations to be precise. Making two loops increased the reliability of the reading (since it seems the first iteration is really slow because of cache issues and what not). For example, you could compare $Val = $Val +1to ... $Val += 1(in this case, the obvious winner is $Val += 1 but it isn't always so evident) The code is as simple as can be, I guess if you don't get it than it's not for you In any case, the results you get might make you change your programming habits! If you do a lot of looping then I suggest you try out the commands in those loops and see what's better. Good luck! EDIT: It's been brought to my attention by chris95219 that GetTickCount() cannot be properly timed. Also if you use the $i and $j variables in your code (both loop counters) you will obviously get incorrect results! TESTED BY YOURS TRUELY: 1. For/Next loops are champions. Try not to use While/Wend or Do/Until 2. If $Val is faster than If $Val = 1 or $Val = TRUE 3. If $Val = 1 is faster than $Val = TRUE 4. If Not $Val is faster than If $Val = 0 or $Val = FALSE 5. If $Val = 0 is faster than If $Val = FALSE 6. < and > are faster than =, >= or <= (Wow!) 7. $i += 1 is faster than $i = $i + 1 $i -= 1 is faster than $i = $i - 1 $i *= 1 is faster than $i = $i * 1 $i /= 1 is faster than $i = $i / 1 8. If doing a lot of verifications on a single variable: Switch is fastest, Select is second (but slow) and If is slowest. 9. If $Val is a string, If Not $Val is faster than If $Val = "" If $Val is faster than If $Val <> "" 10. When doing binary operations, If $Val -128 > 0 is twice as fast as If BitAnd($Val, 128). 11. Using Hex numbers is faster than using decimal numbers 12 Replacing dec/hex numbers by variables slows down execution. Use hex/dec numbers when possible 13. Longer variable names = longer execution time. Keep variable names short and clear! 14. StringRegExpReplace() is slower than StringReplace(). Use it only if necessary! 15. StringRegExp() is slower than StringInStr(). Use only if necessary! 16. Opt("ExpandEnvStrings",1) makes $Val = "%TEMP%" faster than $Val = EnvGet("temp") or $Val = @TempDir 17. $Val = @TempDir is faster than $Val = EnvGet("temp") 18. Opt("ExpandVarStrings",1) makes $Val = "$String$" slightly faster than $Val = $String 19. However $Val = "@TempDir@" is slower than $Val = @TempDir (go figure!)
    1 point
  7. Thank you for you attention. I find a solution for the problem in this topic. Below the working script code with modifications for solve the problem. The @OSVersion don't returns WIN_10 in Windows 10, returns 9600. But at last the script is finding the image on screen with right coordinates. #include <ImageSearch2015.au3> AutoItSetOption("MouseCoordMode", 1) #AutoIt3Wrapper_Res_HiDpi=Y HotKeySet("p", "checkForImage") HotKeySet("o", "showCoords") If @OSVersion="WIN_10" Then DllCall("Shcore.dll","long","PROCESS_DPI_AWARENESS",1) Else DllCall("User32.dll","bool","SetProcessDPIAware") EndIf Global $x = 0, $y = 0 ConsoleWrite(@OSBuild & @CR) ConsoleWrite(@DesktopWidth & @CR & @DesktopHeight & @CR) Func checkForImage() Local $search = _ImageSearch("tst.bmp", 1, $x, $y, 0) If $search = 1 Then ConsoleWrite($x & @CR & $y & @CR) MouseMove($x, $y, 0) EndIf EndFunc ;==>checkForImage Func showCoords() $mousepos = MouseGetPos() ToolTip($mousepos[0] & "," & $mousepos[1]) ConsoleWrite($mousepos[0] & @CR & $mousepos[1] & @CR) EndFunc ;==>showCoords While 1 Sleep(200) WEnd
    1 point
  8. junkew, Thanks for the hints - got it working now. JustSomeone, This script looks first in the main systray - if it does not find the icon it opens the popup and looks there: #include <GuiToolBar.au3> Global $hSysTray_Handle Global $sTipText = "TestScript" ; Change this to the text you require HotKeySet("q", "_Search") Opt("TrayMenuMode", 3) TrayCreateItem("One") TrayCreateItem("Two") TrayCreateItem("Three") TrayCreateItem("") $mExit_Item = TrayCreateItem("Exit") TraySetState() TraySetToolTip("TestScript") While 1 If TrayGetMsg() = $mExit_Item Then Exit WEnd Func _Search() $hTaskBarHandle = WinGetHandle("[Class:Shell_TrayWnd]", "") ; Find main systray handle and look there first $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then MsgBox(16, "Error", "System tray not found") Exit EndIf $iSystray_ButtonNumber = Get_Systray_Index($sTipText) If Not @error Then _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right") Exit EndIf ; Click on button to open hidden icons ControlClick($hTaskBarHandle, "", "[CLASS:Button; INSTANCE:1]") ; Wait for window and then get handle WinWait("[Class:NotifyIconOverflowWindow]") $hSysTray_Handle = ControlGetHandle("[Class:NotifyIconOverflowWindow]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then MsgBox(16, "Error", "System tray not found") Exit EndIf ; Now look in hidden icons $iSystray_ButtonNumber = Get_Systray_Index($sTipText) If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Could not find icon") Else _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right") Exit EndIf EndFunc ;==>_Show Func Get_Systray_Index($sText) ; Get systray item count Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSystray_ButCount = 0 Then MsgBox(16, "Error", "No items found in system tray") Exit EndIf ; Look for tooltip For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1 If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sText) > 0 Then ExitLoop Next If $iSystray_ButtonNumber = $iSystray_ButCount Then Return SetError(1, 0, -1) ; Not found Else Return $iSystray_ButtonNumber ; Found EndIf EndFunc ;==>Get_Systray_Index That works fine for me - how about you? M23
    1 point
  9. Success :-) AutoItSetOption("WinTitleMatchMode", 2) $handle = WinGetHandle("[CLASS:Chrome_WindowImpl_0; TITLE:Getting the current chrome url]") If @error Then MsgBox(4096, "Error", "Could not find the correct window") Else ; alert the present url MsgBox(4096, "", ControlgetText($handle, "", "Chrome_AutocompleteEditView1" )) ;n redirect the browser ControlSetText ($handle, "", "Chrome_AutocompleteEditView1", "http://alterlife.org/") ControlSend ($handle, "", "Chrome_AutocompleteEditView1", "{enter}") MsgBox(4096, "Error", "The browser has been redirected to http://alterlife.org/.") EndIf
    1 point
×
×
  • Create New...