MasonMill Posted July 28, 2010 Author Share Posted July 28, 2010 (edited) If @error Then ConsoleWrite("Error Code: " & @error & @CRLF) FileOpen(@ScriptDir & "\consoleread.txt") $words = ConsoleRead() Send($words) ElseIf any help on why this wont work? Edited July 28, 2010 by MasonMill Link to comment Share on other sites More sharing options...
bo8ster Posted July 29, 2010 Share Posted July 29, 2010 I'm just going to kill the ConsoleWrite issue now. The output of ConsoleWrite is viewable in the output section of Scite. Scite captures the stream (both std and error) unless it is a console application. If you are not using Scite for some reason you may not see the output. I suggest you download the latest version of Scite from http://www.autoitscript.com/autoit3/scite/downloads.shtml and proceed from there. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
MasonMill Posted July 29, 2010 Author Share Posted July 29, 2010 Thats what i thought, the output is the white section that you drag downward at the bottom of the editor. After console write it doesn't put anything in the field though. Link to comment Share on other sites More sharing options...
ShawnW Posted July 29, 2010 Share Posted July 29, 2010 Just use a msgbox then. If you don't get the popup with the code then I don't know whats going on, because the only way dllcall doesn't return an array is if there was an error, and without the error code it's hard to help. Link to comment Share on other sites More sharing options...
bo8ster Posted July 29, 2010 Share Posted July 29, 2010 Check again, it will be there. You may have to add new line @CR see it clearly. It will be there with the compile output and stuff. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
MasonMill Posted July 29, 2010 Author Share Posted July 29, 2010 (edited) @Shawn, now that I just put the dll in the @scriptdir it runs, thank you for your patience! It still turns up negative though, i even put in a function to take a screenshot of a small area on the desktop(since i know it wouldnt change colors for more exact match). Any ideas? Here is the script: expandcollapse popup#include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> Global $coords[2] Global $pathToBMP = "C:\Users\..." ; Path to the image you want to find Global $ScreenShot HotKeySet("{F1}", "FindImage") HotKeySet("{F2}", "Screenshot"); takes screenshot of paperdoll tab on options menu While 1 Sleep(100) WEnd Func Screenshot() _GDIPlus_Startup() _ScreenCapture_SetBMPFormat(2) _ScreenCapture_Capture(@ScriptDir & "\BMP1_screenshot.bmp", 61, 50, 122, 60, False) _GDIPlus_Shutdown() EndFunc Func FindImage() ; The parameters for _ImageSearch are _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance) ; Most are self explainitory but $resultPosition = 1 or 0. ; It determins what coords are returned, 1 for center of image and 0 for top left. $result = _ImageSearch(@ScriptDir & "\BMP1_screenshot.bmp", 0, $coords[0], $coords[1], 5) If $result = 1 Then Send("{ESCAPE}") EndIf If @error Then MsgBox(0, "Error", "ERROR!") EndIf If $result = 1 Then MsgBox(0, "Result", "Found!") ElseIf $result = 0 Then MsgBox(0, "Result", "Not Found!") EndIf EndFunc ;==>FindImage ; ------------------------------------------------------------------------------ ; ; 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) Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance) EndFunc ;==>_ImageSearch Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance) ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage) ;If @error Then ConsoleWrite("Error Code: " & @error & @CRLF & @CR) ;EndIf ; If error exit If $result = "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 $resultPosition = 1 Then $x = $x + Int(Number($array[4]) / 2) $y = $y + Int(Number($array[5]) / 2) EndIf Return 1 EndFunc ;==>_ImageSearchArea I slapped an error check in there @Bo8ster, i would really like to understand why i cant read consolewrite. I put ConsoleWrite("Error Code: " & @error & @CRLF & @CR) in the function but there is still no writing in thewhite field under the editor. Any ideas on why? Thanks! Edited July 29, 2010 by MasonMill Link to comment Share on other sites More sharing options...
ShawnW Posted July 29, 2010 Share Posted July 29, 2010 (edited) It still turns up negative thoughnegative as in not found, or function error?Edit: If it is not found I would ask what section of the screen you are trying to match against. Some flash, and certain other video rendering techniques are strange in that they overlay the screen. I'm no video wizard I have just noticed sometimes when you screenshot a video the video area will be blank in the shot. I also noticed that in these cases the imagesearch.dll cannot find parts of that video either. Not saying this is the case but just an instance where it's not perfect. Edited July 29, 2010 by ShawnW Link to comment Share on other sites More sharing options...
MasonMill Posted July 29, 2010 Author Share Posted July 29, 2010 Comes up not found. When i look at the screenshot it shows the portion of the desktop it should. Its weird, on another image find script that turns the BMP to a string, i cant get it to work either. The BMP is 24 bit so its not that, i wonder if its something stupid like that though preventing me. Link to comment Share on other sites More sharing options...
MasonMill Posted July 29, 2010 Author Share Posted July 29, 2010 omgood frigging god, IT WORKS! asldjfkalsdkfjaksdjfs found a different 64bit DLL that worked this time! YAY thank you thank you thank you thank you thank you. Dude thank you ShawnW, Bo8ster, melba and anyone else who played a part in my newbiness. Thanks guys!!! Link to comment Share on other sites More sharing options...
ShawnW Posted July 29, 2010 Share Posted July 29, 2010 Your welcome, it also should have worked if you use compile and choose x86 and run the .exe version as I think I mentioned. I say should though because it worked for me, no extensive testing. Anyway glad you got it working! -Shawn Link to comment Share on other sites More sharing options...
MasonMill Posted July 29, 2010 Author Share Posted July 29, 2010 hrm, when i dont get a match though i get an error: $x = Int(Number($array[2])) $x = Int(Number(^ ERROR Error: Array variable has incorect number of subscripts or subscript dimension range exceeded. Link to comment Share on other sites More sharing options...
ShawnW Posted July 29, 2010 Share Posted July 29, 2010 It's possible the 64 bit version of the dll returns things differently than the 32 bit. The autoit wrapper functions were designed to work based on the other return values where if there is no match then $result[0] = 0. If this is not the case then you need to do some testing to see what is returned. In this situation what I would do is 1st #include <array.au3> simply because _ArrayDisplay is awesome for debugging when dealing with arrays. Then I would put this in the _ImageSearchArea() function. ; Right after $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage) ; Put this _ArrayDisplay($result) Then run a test on something you know it will find. Note what it is returning. Then run a test on something that it will not find. See what it returns. Then make sure the logic on the rest of the function lines makes sense in dealing with the values returned. Link to comment Share on other sites More sharing options...
bo8ster Posted July 29, 2010 Share Posted July 29, 2010 @Bo8ster, i would really like to understand why i cant read consolewrite. I put ConsoleWrite("Error Code: " & @error & @CRLF & @CR) in the function but there is still no writing in thewhite field under the editor. Any ideas on why? Thanks! Please post all the output in the output section of Scite. Example >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\....\workspace.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>08:22:48 Starting AutoIt3Wrapper v.2.0.1.24 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X64 OS:X86) >Running AU3Check (1.54.19.0) from:C:\Program Files\AutoIt3 +>08:22:48 AU3Check ended.rc:0 >Running:(3.3.6.0):C:\Program Files\AutoIt3\autoit3.exe "C:\...\workspace.au3" +>08:22:57 AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 10.825 Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
MasonMill Posted July 29, 2010 Author Share Posted July 29, 2010 (edited) @Bo8ster, Jos asked if i was pushing F5 to run my script. I didnt know you could press F5, i always right clicked the file to execute. So, now i see my console! Thank you for you time and patience helping me. I love console, a lot of info comes through there! @ShawnW & Bo8ster, im getting error 0 which means its found the image in that area but im getting this: Error Code: 0 C:\Users\Mason\Desktop\scripts\ImageSearch\Ultimate Image Search.au3 (101) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $x = Int(Number($array[2])) $x = Int(Number(^ ERROR ->18:29:01 AutoIT3.exe ended.rc:1 >Exit code: 1 Time: 6.1500 with array display i get: [0]|0 [1]|0 [2]|0 [3]|1920 [4]|1080 [5]|*5 C:\Users\Mason\Desktop\scripts\optionstab Edited July 29, 2010 by MasonMill Link to comment Share on other sites More sharing options...
bo8ster Posted July 30, 2010 Share Posted July 30, 2010 If was to guess, I would say the array is contained within a loop and the array's contents gets updated every time the loop executes. For some reason the contents is getting messed up, use #AutoIt3Wrapper_run_debug_mode=Y to trace the issue. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
MasonMill Posted July 30, 2010 Author Share Posted July 30, 2010 This is what it looks like with the wrapper: !> Starting in DebugMode.. Line: @error-@extended: Line syntax 0001: 0-0: #AutoIt3Wrapper_run_debug_mode=Y 0003: 0-0: #include <GDIPlus.au3> 0004: 0-0: #include <ScreenCapture.au3> 0005: 0-0: #include <WinAPI.au3> 0006: 0-0: #include <array.au3> 0009: 0-0: Global $coords[2] 0010: 0-0: Global $pathToBMP = "C:\Users\Mason\Desktop\scripts\optionstab" ; Path to the image you want to find 0011: 0-0: Global $ScreenShot = "\BMP1_screenshot.bmp" 0013: 0-0: HotKeySet("{F1}", "FindImage") 0014: 0-0: HotKeySet("{F2}", "Screenshot"); takes screenshot of paperdoll tab on options menu 0017: 0-0: While 1 0018: 0-0: Sleep(10000) 0037: 0-0: $result = _ImageSearch($pathToBMP, 0, $coords[0], $coords[1], 5) 0084: 0-0: Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance) 0090: 0-0: If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage 0091: 0-0: $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage) 0093: 0-0: _ArrayDisplay($result) 0096: 0-0: If $result = "0" Then Return 0 0100: 0-0: $array = StringSplit($result[0], "|") 0102: 1-0: $x = Int(Number($array[2])) C:\Users\Mason\Desktop\scripts\ImageSearch\Ultimate Image Search_DebugIt.au3 (232) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $x = Int(Number($array[2])) $x = Int(Number(^ ERROR ->22:17:29 AutoIT3.exe ended.rc:1 >Exit code: 1 Time: 12.808 Link to comment Share on other sites More sharing options...
MasonMill Posted July 30, 2010 Author Share Posted July 30, 2010 So because the array is defined in the DLL there is nothing i can do? Link to comment Share on other sites More sharing options...
MasonMill Posted August 2, 2010 Author Share Posted August 2, 2010 (edited) Ok so ive been beating my head into the wall all weekend trying to figure this damn thing out. I thought i got it working but i think i accidentally deleted an endif or something that made it true all the time, or something was working properly and i didnt see what it was and degressed or something else. At any rate,i pasted the original code back in and its returning 0 right now. I dont know if it is because the DLL isnt working properly, which makes more sense than anything else because i dont think there is a problem with the code. Who knows... Does anyone see any blatant mistakes that im just over looking? I am getting an error code 1, which means image not found. I am using the x64 DLL. Here is my code: expandcollapse popup; ------------------------------------------------------------------------------ ; ; 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 ; ;=============================================================================== #AutoIt3Wrapper_run_debug_mode=Y #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> #include <array.au3> Global $coords[2] Global $ScreenShot = "\BMP1_screenshot.bmp" HotKeySet("{F1}", "FindImage") HotKeySet("{F2}", "Screenshot"); takes screenshot of a small portion of the desktop (easy to find) While 1 Sleep(10000) WEnd Func Screenshot() _GDIPlus_Startup() _ScreenCapture_SetBMPFormat(2) _ScreenCapture_Capture(@ScriptDir & $ScreenShot, 61, 50, 122, 60, False) _GDIPlus_Shutdown() EndFunc Func FindImage() ; The parameters for _ImageSearch are _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance) ; Most are self explainitory but $resultPosition = 1 or 0. ; It determins what coords are returned, 1 for center of image and 0 for top left. $result = _ImageSearch($ScreenShot, 0, $coords[0], $coords[1], 200) If $result = 1 Then Send("{ESCAPE}") MsgBox("", "imagesearch", "image found") EndIf EndFunc ;==>FindImage ; _ImageSearch($pathToBMP, 0, $coords[0], $coords[1], 5) Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance) Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance) EndFunc ;==>_ImageSearch ; _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance) Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance) ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage) If @error Then MsgBox("", "error", "Error Code: " & @error & @CRLF) _ArrayDisplay($result) ; If error exit ;if $result[0]="0" then return 0 if IsArray($result) Then MsgBox("", "Result","it IS an array, and it returned:"+$result+"") if $result[0]="0" then return 0 Else MsgBox("", "Result","it is NOT an array, and it returned:"+$result+"") if $result="0" then return 0 EndIf ; 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 $resultPosition=1 then $x=$x + Int(Number($array[4])/2) $y=$y + Int(Number($array[5])/2) endif return 1 EndFunc and the wrapper looks like: expandcollapse popup>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\Mason\Desktop\scripts\Ultimate Image Search.au3" /autoit3dir "C:\Program Files (x86)\AutoIt3" /UserParams +>10:23:11 Starting AutoIt3Wrapper v.2.0.1.24 Environment(Language:0409 Keyboard:00000409 OS:WIN_7/ CPU:X64 OS:X64) >Running AU3Check (1.54.19.0) from:C:\Program Files (x86)\AutoIt3 +>10:23:11 AU3Check ended.rc:0 >Running:(3.3.6.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Mason\Desktop\scripts\Ultimate Image Search.au3" !> Starting in DebugMode.. Line: @error-@extended: Line syntax 0032: 0-0: #AutoIt3Wrapper_run_debug_mode=Y 0034: 0-0: #include <GDIPlus.au3> 0035: 0-0: #include <ScreenCapture.au3> 0036: 0-0: #include <WinAPI.au3> 0037: 0-0: #include <array.au3> 0040: 0-0: Global $coords[2] 0041: 0-0: Global $ScreenShot = "\BMP1_screenshot.bmp" 0043: 0-0: HotKeySet("{F1}", "FindImage") 0044: 0-0: HotKeySet("{F2}", "Screenshot"); takes screenshot of a small portion of the desktop (easy to find) 0047: 0-0: While 1 0048: 0-0: Sleep(10000) 0053: 0-0: _GDIPlus_Startup() 0054: 0-0: _ScreenCapture_SetBMPFormat(2) 0056: 0-0: _ScreenCapture_Capture(@ScriptDir & $ScreenShot, 61, 50, 122, 60, False) 0058: 0-0: _GDIPlus_Shutdown() 0060: 0-0: EndFunc 0067: 0-0: $result = _ImageSearch($ScreenShot, 0, $coords[0], $coords[1], 200) 0081: 0-0: Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance) 0087: 0-0: if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage 0088: 0-0: $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage) 0090: 1-0: If @error Then MsgBox("", "error", "Error Code: " & @error & @CRLF) 0092: 0-0: _ArrayDisplay($result) 0097: 1-0: if IsArray($result) Then 0101: 0-0: MsgBox("", "Result","it is NOT an array, and it returned:"+$result+"") 0102: 0-0: if $result="0" then return 0 0069: 0-0: If $result = 1 Then 0074: 0-0: EndFunc ;==>FindImage 0049: 0-0: WEnd 0048: 0-0: Sleep(10000) +>10:23:22 AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 12.217 Any help would be greatly appreciated! edit: i forgot to add that the array $result comes out as: [0]|0 [1]|0 [2]|0 [3]|1920 [4]|1080 [5]|*200 \BMP1_screenshot.bmp Edited August 2, 2010 by MasonMill Link to comment Share on other sites More sharing options...
MasonMill Posted August 2, 2010 Author Share Posted August 2, 2010 Got it working, it had to do with my @scriptdir syntax. wasn't reading the correct file. Thanks for everyone's help and patience, i know im not great at programming but i really enjoy it! Link to comment Share on other sites More sharing options...
ShawnW Posted August 3, 2010 Share Posted August 3, 2010 Glad you got it working, just in case I need it in the future could you attach the 64 bit dll. I have always had luck with the 32 if i compile that way, but the day may come when it's needed and better to have it now than try and find it then. Also, I may start writing in checks and having my programs start knowing which version of the dll to use and include them both. Shawn Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now