Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/01/2017 in all areas

  1. After having lot of issues myself with getting ImageSearch to work I decided to make topic with explanation how to proper use this script. Here is link of original topic at this topic: Credits to kangkeng for creating such useful piece of code. What is ImageSearch? It's script that find part of screen which you before defined with given image. When should I use ImageSearch? You should use it whenever it's not possible or unlikely that pixelsearch will give what you need. So how can I use ImageSearch and enjoy it's awesome benefits? First of all to avoid mostly caused problems I recompiled DLLs for both architectures which you can download at end of this post. When you pick your package you should place both ImageSearch.au3 and ImageSearch.dll inside script folder. Usage Example: First of all take picture of what you want to search for (print screen + paint + corp + save as bmp). Place that picture in script directory (I named my picture checkImage (checkImage.bmp is full name with extension). You must include ImageSearch.au3 in your script. ImageSearch.au3 consist of 2 Functions you can use: _ImageSearch and _ImageSearchArea Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify a desktop region to search Values to put in for _ImageSearch function (entire screen search) ($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance, $HBMP=0) Values to put in for _ImageSearchArea function (you declare part of screen to be searched) ($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance,$HBMP=0) Description of parameters from ImageSearch.au3 itself: ; 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 Example of my script using _ImageSearch ( entire screen search) #include <ImageSearch.au3> HotKeySet("p", "checkForImage") global $y = 0, $x = 0 Func checkForImage() Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0) If $search = 1 Then MouseMove($x, $y, 10) EndIf EndFunc while 1 sleep(200) WEnd Example of my script using _ImageSearchArea #include <ImageSearch.au3> HotKeySet("p", "checkForImage") global $y = 0, $x = 0 Func checkForImage() local $search = _ImageSearchArea('check5.bmp', 1, 800, 40, 900, 80, $x, $y, 0) If $search = 1 Then MouseMove($x, $y, 10) EndIf EndFunc while 1 sleep(200) WEnd I would like to apologize if by writing this I offended any of member that thinks this script is too simple to even have it explained, it's just as me being new to autoIt it took me so much time getting around errors and making this script to work. Thanks for reading, if you bump on any problems using it post it here, I will try to help you fixing it and update topic for further reference. Download links: 32bit: ImageSearch 32bit.rar 64bit: ImageSearch 64 bit.rar
    1 point
  2. Icy, InputBox would seem to be what you are looking for. M23
    1 point
  3. water

    all the help i can get

    Welcome to AutoIt and the forum! Maybe you are looking for the Vollatran installation tool: You set up an Ini -file with the programs to install. The rest gets done by the tool.
    1 point
  4. rootx, Firstly you are creating the ListView using the UDF, so you cannot use GUICtrlSendMsg - the creation function returns a handle and not a ControlID - you need to use _SendMessage instead. Here is your script amended to use a HotKey to toggle the focus lines: #include <Misc.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <ListBoxConstants.au3> #include <GuiListBox.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <File.au3> #include <FileConstants.au3> #include <StaticConstants.au3> #include <GuiImageList.au3> #include <GuiStatusBar.au3> #include <WinAPI.au3> #include <GDIPlus.au3> #include <Date.au3> #include <IE.au3> #include "GUIListViewEx.au3" HotKeySet("{ESC}", "On_Exit") HotKeySet("^f", "_FocusSwitch") Global $fFocus = False Global $bChanged ;Graphics Global $icod = @ScriptDir & "\img\defico.jpg" Global $bg = @ScriptDir & "\img\def.jpg" Global $ini = @ScriptDir & "\ini.ini" For $z = 1 to 4 IniWriteSection($ini,@ScriptDir&"\data\"&$z,"") Next $sect = IniReadSectionNames($ini) For $s = 1 To UBound($sect) - 1 IniWrite($ini,$sect[$s],"name",$s) IniWrite($ini,$sect[$s],"img",@ScriptDir&"\img\"&$s&".jpg") IniWrite($ini,$sect[$s],"icon",@ScriptDir&"\ico\"&$s&".ico") IniWrite($ini,$sect[$s],"background",@ScriptDir&"\img\"&$s&".jpg") Next $GUIH="600" $GUIW="1024" $LsX="172" $LsY="33" $LsW="340" $LsH="481" $Xcolor = "0x0000FFFF" $Xfcolor = "0x0000FFFF" _GDIPlus_Startup() $Form1 = GUICreate("My LIB", 1024, 600, -1, -1) GUICtrlSetDefColor($Xfcolor) GUICtrlSetDefBkColor($Xcolor) $Pic2 = GUICtrlCreatePic($bg, 820, 10, 200, 200, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE, $SS_SUNKEN, $WS_BORDER)) ;Create listview $hListView = _GUICtrlListView_Create($Form1, "", 0, 0, 320, 600) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES)) ; block resizing of columns ControlDisable($Form1, "", HWnd(_GUICtrlListView_GetHeader($hListView))) ;_GUICtrlListView_SetBkColor($hListView, $Xcolor) ;_GUICtrlListView_SetTextBkColor($hListView, $Xcolor) ;_GUICtrlListView_SetTextColor($hListView, 0x0000000) ;Add columns _GUICtrlListView_InsertColumn($hListView, 0, "", 320) _GUICtrlListView_InsertColumn($hListView, 1, "Path", 0) _GUIListViewEx_MsgRegister(False) ;<--------------------------------------- GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST') GUISetState(@SW_SHOW) ;Slide Effect Global $hGfx = _GDIPlus_GraphicsCreateFromHWND($Form1) ;clip control elements Global $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $guiw, $guih) Global $hChild = _WinAPI_GetWindow($Form1, $GW_CHILD) Global $aRect Do $aRect = ControlGetPos($hChild, "", 0) _GDIPlus_RegionCombineRect($hRegion, $aRect[0], $aRect[1], $aRect[2], $aRect[3], 3) $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT) Until Not $hChild _GDIPlus_GraphicsSetClipRegion($hGfx, $hRegion) _GDIPlus_RegionDispose($hRegion) Global $hBmp1 = _GDIPlus_ImageLoadFromFile($bg) _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp1, 0, 0, $guiw, $guih) read() _GUICtrlListView_RegisterSortCallBack($hListView) While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $Form1 Switch $aMsg[0] Case $GUI_EVENT_CLOSE _GDIPlus_ImageDispose($hBmp1) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_Shutdown() EndSwitch EndSwitch WEnd Func _FocusSwitch() $fFocus = Not $fFocus If $fFocus Then _SendMessage($hListView, $WM_CHANGEUISTATE, 65537, 0) Else _SendMessage($hListView, $WM_CHANGEUISTATE, 65538, 0) EndIf EndFunc ; ======================================================== ; This thing is responcible for click events ; ======================================================== Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $Index = DllStructGetData($tInfo, "Index") If DllStructGetData($tInfo, "Index") = -1 Then ;ConsoleWrite("no item" & @CRLF) Else ;GUICtrlSendMsg($hListView, $WM_CHANGEUISTATE, 65537, 0 );<--------------------------------------------??? Local $iItemText = _GUICtrlListView_GetItemText($hListView, DllStructGetData($tInfo, "Index"), 1) $pics = IniRead($ini, $iItemText, "img", "") If FileExists($pics) Then GUICtrlSetImage($Pic2, $pics) Else GUICtrlSetImage($Pic2, $icod) EndIf $item = StringSplit(_GUICtrlListView_GetItemTextString($hListView, $Index), '|') $itemx = $item[1] $item2 = IniRead($ini, $iItemText, "background", "") Local $n = 1, $guihx = $guih + 50 If FileExists($item2) Then Local $hBmp2 = _GDIPlus_ImageLoadFromFile(IniRead($ini, $iItemText, "background", "")) For $x = -$guiw To 0 Step 50 _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx) Next _GDIPlus_ImageDispose($hBmp2) Else Local $hBmp2 = _GDIPlus_ImageLoadFromFile($bg) For $x = -$guiw To 0 Step 50 _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx) Next _GDIPlus_ImageDispose($hBmp2) EndIf EndIf Case $LVN_KEYDOWN $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam) $iKey = DllStructGetData($tInfo, "VKey") ; Get current selection $aLastSel = StringSplit(_GUIListViewEx_GetLastSelectedItem(), "|") Switch $iKey Case 38 ; Move up unless at top $iCurrItem = $aLastSel[2] - 1 If $iCurrItem < 0 Then $iCurrItem = 0 EndIf _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem) Case 40 ; Move down unless at bottom $iCurrItem = $aLastSel[2] + 1 If $iCurrItem >= _GUICtrlListView_GetItemCount($hWndFrom) Then $iCurrItem = _GUICtrlListView_GetItemCount($hWndFrom) - 1 EndIf _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem) EndSwitch EndSwitch EndSwitch $iRet = _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam);<--------------------------------------- Return $iRet;<--------------------------------------- Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam) Return $HTCAPTION EndFunc ;==>WM_NCHITTEST Func On_Exit() Exit EndFunc ;==>On_Exit Func read() Local $tot = 0 If FileExists($ini) Then $hImage = _GUIImageList_Create(48, 48, 5, 1) _GDIPlus_Startup() $aArrays = IniReadSectionNames($ini) _ArrayColInsert($aArrays, 1) For $s = 1 To UBound($aArrays) - 1 $aArrays[$s][1] = StringRegExp($aArrays[$s][0], '.*\\(.*)\\', 1)[0] Next _ArrayColDelete($aArrays, 1, True) If Not @error Then For $i = 1 To UBound($aArrays) - 1 $n = IniRead($ini, $aArrays[$i], "name", "") $z = IniRead($ini, $aArrays[$i], "icon", "") ;load icon and upscale the icon to 48x48 pixels $hBitmap = _GDIPlus_BitmapCreateFromFile($z) $hBitmap_scaled = _GDIPlus_ImageResize($hBitmap, 48, 48) $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_scaled) _GDIPlus_BitmapDispose($hBitmap_scaled) _GDIPlus_BitmapDispose($hBitmap) $ico = _GUIImageList_Add($hImage, $hBitmap_GDI) _GUICtrlListView_SetImageList($hListView, $hImage, 1) _GUICtrlListView_AddItem($hListView, $n, $ico) _GUICtrlListView_AddSubItem($hListView, $i - 1, $aArrays[$i], 1) $tot += 1 Next $aLVArray = _GUIListViewEx_ReadToArray($hListView);<--------------------------------------- $iLV_Index = _GUIListViewEx_Init($hListView, $aLVArray, 0, 0, True, 32 + 512);<--------------------------------------- ; Set required colours for ListView elements - change = pink field when selected;<--------------------------------------- Local $aSelCol[4] = [Default, Default, Default, "0xFFCCCC"];<--------------------------------------- _GUIListViewEx_SetDefColours($iLV_Index, $aSelCol);<--------------------------------------- _GDIPlus_Shutdown() EndIf EndIf EndFunc ;==>read Func _GUIListViewEx_GetLastSelectedItem($iLV_Index = 0) ; Check valid index Switch $iLV_Index Case 1 To $aGLVEx_Data[0][0] ; Valid index Case Else ; Get active ListView $iLV_Index = _GUIListViewEx_GetActive() ; If no ListView active If $iLV_Index = 0 Then Return SetError(1, 0, "") EndSwitch ; Read last selected item Local $iRow = $aGLVEx_Data[$iLV_Index][20] Local $iCol = $aGLVEx_Data[$iLV_Index][21] ; Check selection has been made If $iRow = -1 Or $iCol = -1 Then Return SetError(2, 0, "") ; Return selection details Return $iLV_Index & "|" & $iRow & "|" & $iCol EndFunc There is fairly fundamental difference between handles and ControlIDs - I have explained it many times before - and you really need to be sure you understand it. Please ask if you have any questions. M23
    1 point
  5. I am running AutoIt version 3.3.14.2. And, if you look at the User Defined (date) Functions in the Date.au3 include file, you should notice _DateIsValid() is used to check the dates that enter any of the functions with date as a parameter, and written by Jos. It appears the Date functions are already valid _DateIsValid() format compatible. In the AutoIt help file it says to use "YYYY/MM/DD[ HH:MM:SS]" format for the $sStartDate, $sEndDate, and $sDate parameters of the _DateDiff(), _DateTimeFormat(), and the _DateAdd() functions. The help file should include all of the valid _DateIsValid() formats for these mentioned parameters, as shown in the _DateTimeSplit function in the AutoIt help, in my opinion. The Date UDF's return dates in the "yyyy/MM/dd hh:mm:ss" format. So I have included _DateTimeFormatEx function. This UDF will convert _DateIsValid formats, including the "yyyy/MM/dd hh:mm:ss" format, to any format. So the original date format can be easily retrieved after using the Date functions, if so desired. #include <Date.au3> ; Note date formats are Not in the "yyyy/MM/dd hh:mm:ss" format, yet still work. ConsoleWrite(_DateDiff('h', "1970-01-01T14:00:00", "1970.01.02 00:00") & " hrs" & @CRLF) ; Returns 10 hrs ConsoleWrite(_DateTimeFormat("1970.11.01T14:00:00", 0) & @CRLF) ; Returns 01/11/1970 2:00:00 PM ConsoleWrite(_DateTimeFormatEx(_DateAdd('s', 36001, "1970-01-01T13:30:00"), "yyyy-MM-ddTHH:mm:ss") & @CRLF) ; Returns 1970-01-01T23:30:01 (same format as input date format) ConsoleWrite(_DateTimeFormatEx("1970.11.01T02:30:00", "yyyy-MMMM-dd H:mm:ss") & @CRLF) ; Returns 1970-November-01 2:30:00 ConsoleWrite(_DateTimeFormatEx("1970.11.01T02:30:00", "MM.dd.yyyy") & @CRLF) ; Returns 11.01.1970 ; Format date time using a format string. ; $sDate: input date in any of the valid _DateIsValid function formats. ; Valid DateIsValid() formats:- ; "yyyy/MM/dd[ hh:mm[:ss]]" or "yyyy/MM/dd[Thh:mm[:ss]]" ; "yyyy-MM-dd[ hh:mm[:ss]]" or "yyyy-MM-dd[Thh:mm[:ss]]" ; "yyyy.MM.dd[ hh:mm[:ss]]" or "yyyy.MM.dd[Thh:mm[:ss]]" ; (Remove optional square brackets for use in the $sFormat parameter.) ;$sFormat: A string representing the format for the output appearance. ; See _GUICtrlDTP_SetFormat function in AutoIt Help file for format string characters. ; Func _DateTimeFormatEx($sDate, $sFormat = "yyyy/MM/dd hh:mm:ss") ; Verify If InputDate is valid If Not _DateIsValid($sDate) Then Return SetError(1, 0, "") EndIf $hGui = GUICreate("") $idDate = GUICtrlCreateDate($sDate, 10, 10) GUICtrlSendMsg($idDate, 0x1032, 0, $sFormat) ; or "dddd, MMMM d, yyyy hh:mm:ss tt"); or "hh:mm tt" $FormatedDate = GUICtrlRead($idDate) GUIDelete($hGui) Return $FormatedDate EndFunc ;==>_DateTimeFormatEx
    1 point
  6. Subz

    Unusual behavior

    Looks like your Input box is interfering with your button, you'll notice that when you click the button its reading the inputbox first which appears to change the Paused state.
    1 point
  7. And another example that generates unique file names with a format that chronologically sorts on name. #include <ScreenCapture.au3> HotKeySet("{PRINTSCREEN}", "SS") HotKeySet("{ESC}", "Terminate") While 1 Sleep(100) WEnd ; Can provide 999 unique file names per hour in the format of SCYYYYMMDDHH_001.jpg to SCYYYYMMDDHH_999.jpg Func SS() Local $aFileName, $iCount = 0 While 1 $iCount += 1 $aFileName = @MyDocumentsDir & "\SC" & @YEAR & @MON & @MDAY & @HOUR & _ "_" & StringRight("00" & $iCount, 3) & ".jpg" If FileExists($aFileName) = 0 Then ExitLoop WEnd _ScreenCapture_Capture($aFileName) ShellExecute($aFileName) EndFunc ;==>SS Func Terminate() Exit EndFunc ;==>Terminate
    1 point
  8. Like this? #include <ScreenCapture.au3> #include <File.au3> $HMSDMYY = @HOUR & "_" & @MIN & "_" & @sec &"_" & @MDAY & @MON & @year & ".jpg" HotKeySet("{PRINTSCREEN}", "SS") While 1 Sleep(100) WEnd Func SS() _ScreenCapture_Capture(@MyDocumentsDir & "\screenshot_" & $HMSDMYY) EndFunc Added minutes and seconds for in case you want more in the Hour?
    1 point
  9. Annonyreeder, In this If IsObj($oFound) Then _IEAction ($oFound, "click") MsgBox(16, "Success", "Password23 with a captial P (Roles have been set)") Else MsgBox(16, "Failed", "Not found.") EndIf Do you still get the success msgbox ?
    1 point
  10. Usually imagesearch library is used for game automatation. Pixel search as well. FF udf it's much more powerful I find. But none of them are trustable 100%
    1 point
×
×
  • Create New...