Leaderboard
Popular Content
Showing content with the highest reputation on 08/21/2021 in all areas
-
Screen scraping
SkysLastChance reacted to Nine for a topic
Screen scraping means a way to read / write on the representation of the current screen. You can, with this UDF, read the actual foreground of the screen or a background window. Hidden or minimized window are not supported. I tried to optimize the use of AutoIt as much as I could, but some actions require the performance of a DLL. I have found multiple threads and others UDF discussing this subject but never found an optimized approach to this issue without gathering everything inside a large DLL. The examples I am providing show how to use a background window (even if it is in the foreground when you run it directly with Scite) or use the current screen. Reading current screen is faster (about 20-30 ms faster) than reading a background window. You need to first initialize the structure based on width and height. You can reuse the structure as long as you want if the dimensions do not change. You will need to make a new initialize if dimensions are changing. You do not need (this way) to have the actual size of a window. You can decide to reduce the dimensions to increase performance. Supports x86 and x64. The following functions are included in the UDF : _GetScreen_Initialize($iWidth, $iHeight) _GetScreen_GetScreen() _GetScreen_GetWindow($hWnd, $iFlag = 0) _GetScreen_GetPixel($iX, $iY) _GetScreen_SetPixel($iX, $iY, $iValue) _GetScreen_SearchArea($iLeft, $iTop, $iRight, $iBottom, $iColor, $iStart = 1) _GetScreen_SearchAll($iColor, $iStart = 1) _GetScreen_PixelReplaceArea($iColorFrom, $iColorTo, $iLeft, $iTop, $iRight, $iBottom) _GetScreen_PixelReplaceAll($iColorFrom, $iColorTo) _GetScreen_CheckSumArea($iLeft, $iTop, $iRight, $iBottom) _GetScreen_SaveFile($sFileName) _GetScreen_GetBitMap() Version 2022-04-17 * Added new optional parameter $iFlag to _GetScreen_GetWindow 0 = full window for Win 7 and over 1 = client area for Win 7 and over 2 = full window for Win 10 and over (this can be used with applications (like Chrome) that do not support WM_PRINT or WM_PRINTCLIENT messages) Version 2021-11-28 * Corrected a bug in SearchArea Version 2021-08-30 * Fixed bugs related to areas * Added support to repetitive searches in the same area * Added a function to make a CheckSum of an area * Added an additional example Version 2021-08-24 * Removed unused structure * Harmonized code Example 1 : show various functions using the _GetScreen_GetWindow (background support) Example 2 : show new functions using _GetScreen_GetScreen() (foreground only but faster) All comments are very much welcome. GetScreen.zip1 point -
Version 2021.8.30.2
10,231 downloads
Use MouseClick() need: #RequireAdmin Dll is already integrated in UDF ! ; #INDEX# =============================================================== ; Title .........: ImageSearch ; AutoIt Version : 3.x ; Language ......: English ; Description ...: Check image Appears or Not and Return the position of an image on the desktop ; Author(s) .....: Dao Van Trong - TRONG.LIVE ; ======================================================================= ; #CURRENT# ============================================================= ; _ImageSearch ; _ImageSearch_Area ; _ImageSearch_Wait ; _ImageSearch_WaitArea ; ======================================================================== ;========================================================================= ; ; Author:...........: AutoIT VietNam : Dao Van Trong - TRONG.LIVE ; Description:......: Check image Appears or Not ; Find and return the position of an image on the desktop ; Syntax:........... _ImageSearch_Area, _ImageSearch ; Parameter(s):..... $_ImagePath: The image to locate on the desktop ; May be a list of image by delimited by "|" ; i.e: $_ImagePath = "image1.bmp|image2.bmp|image3.bmp" ; $P_x1 $P_y1: Position of 1st point ; $P_x2 $P_y2: Position of 2nd point - Default is last botton right of desktop ; $_Tolerance: 0 for no tolerance (0-255). Needed when colors of image differ from desktop. e.g GIF ; $_CenterPos: boolen. True will return $array[1] x $array[2] is center of image found. ; False will return top-left position ; Return Value(s):.. Return an array has 3 item ; On Success: $array[0] 1 ; On Failure: $array[0] 0 ; DLL not found or other error: $array[0] -1 ; $array[1] x $array[2]: position of image what found on desktop ; ; Note:............. Use _ImageSearch to search the entire desktop ; _ImageSearch_Area to specify a desktop region to search ; $_ImagePath with more item need more time appear on screen before function can detect. ; Decrease sleep time in the loop to detect faster. But less performance. I.e CPULoad increased ; ;======================================================================== EG 1: ;~ Opt("MustDeclareVars", 1) ;~ #AutoIt3Wrapper_UseX64=y ;~ #AutoIt3Wrapper_Change2CUI=y #RequireAdmin #include "_ImageSearch_UDF.au3" HotKeySet("{Esc}", "_Exit") ; Press ESC for exit Func _Exit() Exit 0 EndFunc ;==>_Exit Global Const $Ask_On_Found = 0 Global Const $Mouse_Move_On_Found = 1 Global Const $Mouse_Click_On_Found = 0 Global Const $iSleep_Time=500 Global $sCount = 0, $_Image_1 = @ScriptDir & "\example.bmp" ; First, use this function to create a file bmp, maybe a desktop icon for example') MsgBox(64 + 262144, 'ImageSearch', 'At first, create a file bmp,' & @CRLF & 'photos that will search on the screen!') _ImageSearch_Create_BMP($_Image_1) ConsoleWrite("! Search for images: " & $_Image_1 & @CRLF & '! Searching on the screen ...' & @CRLF) While 1 ToolTip('(Press ESC for EXIT) Searching ...', 1, 1) Sleep($iSleep_Time) $sCount += 1 Local $return = _ImageSearch($_Image_1) If $return[0] = 1 Then ConsoleWrite('- [' & $sCount & '] Image found:' & " X=" & $return[1] & " Y=" & $return[2] & @CRLF) If $Mouse_Move_On_Found Then MouseMove($return[1], $return[2]) Sleep($iSleep_Time) EndIf If $Mouse_Click_On_Found Then MouseClick("left", $return[1], $return[2]) ToolTip('(Press ESC for EXIT) - [' & $sCount & "] Image found:" & " X=" & $return[1] & " Y=" & $return[2], 1, 1) If $Ask_On_Found Then Local $ask = MsgBox(6 + 262144, 'Success [' & $sCount & ']', 'Image found:' & " X=" & $return[1] & " Y=" & $return[2]) If $ask = 2 Or $ask = 3 Or $ask = 5 Or $ask = 7 Then Exit ;No, Abort, Cancel, and Ignore If $ask = 10 Then _ImageSearch_Create_BMP($_Image_1) ; Continue ;Try Again EndIf EndIf Sleep(200) WEnd Video demo: [+] When any problem or error occurs, please make sure that:- Downloaded and used the latest version.- Set screen Screen Scale and layout = 100%- Installed display driver.- Tried turning off the antivirus- Full installation: Microsoft Visual C++ Redistributable 2005->2022 [+] You can download the AIO version of the Visual C++ Redistributable here: -> https://www.mediafire.com/file/0ak8dcj9mdn7nyq/VisualCppRedist_AIO_2005-2022_x86_x64_%5Btrong.live%5D.zip/file -> FOR Windows XP: https://www.mediafire.com/file/5m5lnr1kfg73tc9/VisualCppRedist_AIO_2005-2019_x86_XP_%5Btrong.live%5D.zip/file <!> Password for Extract: trong.live [+] The last full version of SCITE4AutoIT supports windows XP: https://www.autoitscript.com/autoit3/scite/download/archive/v19.1127.1402.0-SciTE4AutoIt3.exe1 point -
zPlayer - My own little audio/video player
CYCho reacted to carlvanwormer for a topic
I found that I could make it work if I changed my folder structure to remove spaces. I set out to "fix" the problem by changing the line: $fh = FileOpen(@ScriptDir & "\VLC-Playlist.xspf", 2) to $newstring = '"' & @ScriptDir & "\VLC-Playlist.xspf" & '"' $fh = FileOpen($newstring, 2) ConsoleWrite (" $newstring is " ) ConsoleWrite ($newstring) ConsoleWrite (" $newstring" ) when I run this code I still get the same error results, and the console window shows the quoted string as sent to the system: $newstring is "C:\Users\Carl\Documents\AutoIt\Monk Season 1\VLC-Playlist.xspf" $newstring When I copy this quoted string to the windows console (with or without quotes), it runs the video file. I've attached the playlists from the working (no spaces) and non-working (spaces) runs (removed spaces from folder path). It looks like the VLC program doesn't cope with spaces very well. I can solve the problem by making my directory structure (and probably my filenames) without any spaces. Aside from that problem, your VLC implementation works well. I cannot fully express my gratitude for the help you have given me. I will try to pay it forward. Thanks! Carl VLC-Playlist.xspf VLC-Playlist.xspf1 point -
Here is just some usefull script analyzer: #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> ; just put a FileFullPath to one of your project _UsedInclude_API() _GetAllDependencies("c:\Program Files (x86)\AutoIt3\SciTE\SciTE Jump\SciTE Jump.au3") _UsedInclude_API() _GetAllDependencies("c:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3") _UsedInclude_API() _GetAllDependencies("c:\Program Files (x86)\AutoIt3\SciTE\SciTEConfig\SciteConfig.au3" ) _UsedInclude_API() _GetAllDependencies(@ScriptFullPath) Func _GetAllDependencies($sFileToCheck) GUICreate("My GUI with treeview", 500, @DesktopHeight - 40) Local $idTreeview = GUICtrlCreateTreeView(6, 6, 488, @DesktopHeight - 40 - 12, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) Local $idDisplayitem = GUICtrlCreateTreeViewItem($sFileToCheck, $idTreeview) GUICtrlSetColor(-1, $COLOR_GREEN) __UsedIncludeToTreeView($sFileToCheck, $idDisplayitem) Local $hItem = GUICtrlGetHandle($idDisplayitem) GUICtrlSendMsg($idTreeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem) GUISetState(@SW_SHOW) Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd EndFunc ;==>_GetAllDependencies Func _GetUsedIncludeToArray($sAU3Content) Local $aIncludes = StringRegExp($sAU3Content, '(?im)^\s*#include\s?[''""<](.*)\.au3[''"">]', 3) If @error Then Return SetError(@error, @extended, '') Else Return SetError(0, 0, $aIncludes) EndIf EndFunc ;==>_GetUsedIncludeToArray Func __UsedIncludeToTreeView($sFileToCheck, $idTreeview_ref) $hFile = FileOpen($sFileToCheck, $FO_READ) $sAU3Content = FileRead($hFile) FileClose($hFile) Local $aIncludes = _GetUsedIncludeToArray($sAU3Content) If @error Then Return SetError(@error, @extended, '') Else Local $idDisplayitem, $iNumberOfOccurrences = 0 For $iInclude_Idx = 0 To UBound($aIncludes) - 1 $iNumberOfOccurrences = _UsedInclude_API($aIncludes[$iInclude_Idx]) If $iNumberOfOccurrences = 0 Then $idDisplayitem = GUICtrlCreateTreeViewItem($aIncludes[$iInclude_Idx], $idTreeview_ref) __UsedIncludeToTreeView(_GetDir($sFileToCheck) & $aIncludes[$iInclude_Idx] & '.au3', $idDisplayitem) ElseIf $iNumberOfOccurrences = 1 Then $idDisplayitem = GUICtrlCreateTreeViewItem($aIncludes[$iInclude_Idx] & ' (Was used before: once)', $idTreeview_ref) GUICtrlSetColor(-1, $COLOR_RED) ElseIf $iNumberOfOccurrences = 2 Then $idDisplayitem = GUICtrlCreateTreeViewItem($aIncludes[$iInclude_Idx] & ' (Was used before: twice)', $idTreeview_ref) GUICtrlSetColor(-1, $COLOR_PURPLE) ElseIf $iNumberOfOccurrences > 2 Then $idDisplayitem = GUICtrlCreateTreeViewItem($aIncludes[$iInclude_Idx] & ' (Was used before more then twice)', $idTreeview_ref) GUICtrlSetColor(-1, $COLOR_BLUE) EndIf Next EndIf EndFunc ;==>__UsedIncludeToTreeView Func _UsedInclude_API($sIncludeFileName = Default) Local Static $sIncludeAPI_Static = '|' ; reset If $sIncludeFileName = Default Then $sIncludeAPI_Static = '|' Return EndIf StringReplace($sIncludeAPI_Static, '|' & $sIncludeFileName & '|', '|' & $sIncludeFileName & '|') Local $iNumberOfReplacements = @extended $sIncludeAPI_Static &= $sIncludeFileName & '|' Return SetError(0, 0, $iNumberOfReplacements) EndFunc ;==>_UsedInclude_API Func _GetDir($sFileFullPath) Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Local $aPathSplit = _PathSplit($sFileFullPath, $sDrive, $sDir, $sFileName, $sExtension) Return $sDrive & $sDir EndFunc ;==>_GetDir Have fun. mLipok1 point
-
newniman, The problem was that you had not correctly set the position of the ListView within the GUI - see line #55 of this amended script: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <GuiListView.au3> Global $hGUI, $hListview, $aHit[2] = [-1, -1] ; $aHit contains row & col of marked cell Local $PIPEFILE = "edit-zoom_step_av_value.csv" Local $aRetArray _FileReadToArray($PIPEFILE, $aRetArray, $FRTA_NOCOUNT);, "|") ; As the delimiters are already "!" why bother to split the lines? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $hGUI = GUICreate("Mark Cell in Listview", 1040, 590) Local $cListview = GUICtrlCreateListView("Zoom Step|F3.4|F4.0|F4.5|F5.0|F5.6|F6.3|F7.1|F8.0", 24, 100, 472, 300, $LVS_REPORT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListview = GUICtrlGetHandle($cListview) GUICtrlSetFont($cListview, 8, 800, 0, "MS Sans Serif") For $x = 0 To UBound($aRetArray, $UBOUND_ROWS) - 1 ; As the "|" are already in place, this is much easier to write! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateListViewItem($aRetArray[$x], $cListview) Next Local $cButton = GUICtrlCreateButton("Value?", 150, 430, 70, 20) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY"); good tutorial @ https://www.autoitscript.com/wiki/Tutorial_GUIRegisterMsg While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton MsgBox(0, "Info", "Cell selected: " & _GUICtrlListView_GetItemText($hListview, $aHit[0], $aHit[1]) & @CR, 0, $hGUI) ;MsgBox(0, "Info", "zoom_step selected: " & $aHit[0] & " --> Aperture column selected: " & $aHit[1], 0, $hGUI) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Used by au3check to tell it not to report on "variable not used" when using the parameter "-w 5" - Correct <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListview Switch $iCode Case $LVN_ITEMCHANGED Local $tNMLISTVIEW, $iItem, $aInfo $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) $iItem = DllStructGetData($tNMLISTVIEW, "Item") _GUICtrlListView_SetItemSelected($hListview, $iItem, False) Local $aInfo = GUIGetCursorInfo($hGUI) If $aInfo[2] Then $aInfo = _GUICtrlListView_SubItemHitTest($hListview, $aInfo[0] - 24, $aInfo[1] - 100) ; Upper left position of ListView within GUI - so must match actual position If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then If $aHit[0] > -1 Then _GUICtrlListView_RedrawItems($hListview, $aHit[0], $aHit[0]) If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then $aHit[0] = $aInfo[0] ; Row $aHit[1] = $aInfo[1] ; Col Else $aHit[0] = -1 ; Row $aHit[1] = -1 ; Col EndIf _GUICtrlListView_RedrawItems($hListview, $iItem, $iItem) EndIf EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index Local $uItemState = DllStructGetData($tNMLVCUSTOMDRAW, "uItemState") ; Item state If $dwItemSpec = $aHit[0] Then ; Marked row Switch $iSubItem Case $aHit[1] ; Marked column DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF) ; Forecolor white DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600) ; Backcolor dark blue, BGR Case Else ; Other columns DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000) ; Forecolor black DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF) ; Backcolor white EndSwitch Else ; Other rows DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000) DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF) EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY I also removed most of the include files (which were not all necessary) and cleaned up the _FileReadToArray code which makes creating the ListView items much easier. M231 point