
fsquirrelgpr
Members-
Posts
17 -
Joined
-
Last visited
fsquirrelgpr's Achievements

Seeker (1/7)
0
Reputation
-
Disable Windows Logo Testing Warning
fsquirrelgpr replied to fsquirrelgpr's topic in AutoIt General Help and Support
Thanks for the tip, I should have tried rebooting... I cannot confirm that it is working because the value seems to be changing on startup of one of the keys (maybe from group policy)... I will have to look into this more. -
I am trying to write a script to disable the Windows Logo testing warning that appears in Windows XP when installing an unsigned software driver. The script I wrote to try to do this is: regwrite('HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows NT\Driver Signing', 'BehaviorOnFailedVerify', 'REG_DWORD', 0) regwrite('HKEY_LOCAL_MACHINE\Software\Microsoft\Driver Signing', 'Policy', 'REG_Binary', 0) This does not seem to work though. Has anyone run into this or have any ideas?
-
I use the following code: ;This function waits until the hourglass goes away func WaitUntilDone($max_wait = 120000) local $counter = 0 while(mousegetcursor() = 1) $counter = $counter + $iShortDelay sleep($iShortDelay) if($counter > $max_wait) Then exit_program("Stuck in wait until done loop, exited after " & string($counter) & "ms, mousegetcursor is: " & string(mousegetcursor())) EndIf WEnd sleep($iShortDelay / 4) endfunc Basically The mousegetcursor() is the key line... before running this function, I move the mouse to a position that I know does not have anything that will interfere with the cursor state. Of course I use this in a controlled environment... All of the variables and functions should be self explanatory...
-
how clever is the computer?
fsquirrelgpr replied to locutus243's topic in AutoIt General Help and Support
The method I used for a similar problem is: Use pixelsearch to find the color of the highlighted row. grap 100 or so pixels from about 4 pixels below that first pixel you found (since pixel search searches from top to bottom, it will return the top of the row), put the colors of these pixels into an array Hit the down arrow once Hit the up arrow once Find the highlighted row and again get its Y position (in case you scrolled down) Hit the down arrow once Find the highlight color and make sure its Y position is greater then where you just were If it is, do your work, otherwise you are at the end I used a similar method for scrolling right in Firefox to read a table. Here is some of the code from that which might help if you get stuck (I did not look back to find all functions and global variables so this will not run as-is). func next_box_right($boxes_right = 1) local $boxes_moved = 0 for $boxes_moved = 1 to $boxes_right local $reference_x = 0 local $had_to_move_right = 0 Do ;Always want to have a box to the right of the current box ;so First, go right until a line is found (will always happen unless there is something unaccounted for wrong) $current_position[0] = $current_position[0] + 1 mousemove($current_position[0], $current_position[1], 0) if($current_position[0] = $max_x) Then exit_program("When searching for the next_box_right, could not find the right hand side of the current box.") EndIf until(pixelgetcolor($current_position[0], $current_position[1]) = $bp_grey_table) $reference_x = $current_position[0] ;Now you are at the next box to the right, but not sure if the right side of that box is on the screen yet, so ;do these steps to make sure: local $loop_problem = 0 $current_position[0] = $current_position[0] + 2 while(another_box_to_the_right($current_position[0], $current_position[1]) = 0) ;being here in the loop statement means there is not a right edge to the current box on the screen ;move mouse pointer left to the last BP grey line Do $current_position[0] = $current_position[0] - 1 until(pixelgetcolor($current_position[0], $current_position[1]) = $bp_grey_table) ;now get some pixels to the left of this line so we can find where we were get_pixels_to_left($current_position[0], $current_position[1], $pixels_to_check) ;get_pixels_to_left are stored in the global array $pixel_row ;now actually move over to the right (hit right arrow key a few times) move_right() $loop_problem = $loop_problem + 1 if($loop_problem = 50) Then exit_program("Got stuck in the loop trying to find another box to the right (could not find one after 50 moves to the right).") EndIf sleep($short_delay) ;now set the x coordinate to be where it was before we cold not find another_box_to_the_right $current_position[0] = find_end_of_pixels($pixels_to_check) WEnd ;then move off the dividing line $current_position[0] = $current_position[0] + 3 Next EndFunc func find_end_of_pixels($number_of_pixels) local $temp_x = 0 local $current_x = 0 local $found_match = 1 Do $found_match = 1 for $temp_x = $current_x to $current_x + $pixels_to_check if not (pixelgetcolor($temp_x, $current_position[1]) = $pixel_row[$temp_x - $current_x]) Then $temp_x = $current_x + $pixels_to_check $found_match = 0 EndIf $temp_x = $temp_x + 1 Next $current_x = $current_x + 1 if($current_x = $max_x) Then exit_program("Could not find the pixel row after scrolling to the right") EndIf until $found_match = 1 $current_x = $temp_x + 4 return $current_x EndFunc func another_box_to_the_right($x_start, $y_position) Do $x_start = $x_start + 1 if($x_start = $max_x) Then return 0 EndIf until(pixelgetcolor($x_start, $y_position) = $bp_grey_table) return 1 EndFunc func get_pixels_to_left($x_start, $y_position, $number_of_pixels) local $i local $temp_x = $x_start $temp_x = $x_start - $number_of_pixels for $i = 0 to $number_of_pixels - 1 $pixel_row[$i] = pixelgetcolor($temp_x, $y_position) $temp_x = $temp_x + 1 Next EndFunc func move_right() send("{right}") sleep($short_delay) EndFunc ;This function copies the contents of the current box. It also moves the mouse position to the beginning of the next box. ;Contents will be on the clipboard func copy_current_box() next_box_right() local $copy_temp_x = $current_position[0] Do $copy_temp_x = $copy_temp_x - 1 until(pixelgetcolor($copy_temp_x, $current_position[1]) = $bp_grey_table) $copy_temp_x = $copy_temp_x - 6 mousemove($copy_temp_x, $current_position[1], 0) sleep($short_delay / 2) mousedown("left") Do $copy_temp_x = $copy_temp_x - 1 Until(pixelgetcolor($copy_temp_x, $current_position[1]) = $bp_grey_table) $copy_temp_x = $copy_temp_x + 3 mousemove($copy_temp_x, $current_position[1], 0) sleep($short_delay / 2) mouseup("left") sleep($short_delay / 2) send("^c") sleep($short_delay / 2) mousemove($current_position[0], $current_position[1], 0) EndFunc -
Speeding up CSV File Processing
fsquirrelgpr replied to fsquirrelgpr's topic in AutoIt General Help and Support
Thanks for the advice, I definitely see a couple of ways now that I should be able to speed up what I am doing significantly. To clarify what I had been doing, here is an example of an EDI style file I have created (just a little piece): "DUE_DATE_FIELD:","08/6/2004" "TAX_CHARGE:","CCF (GAS)","16.35","_GAS_" "TOTAL_FIELD:","16.35" "METER_READING_LINE:","CCF (GAS)","70330","0","0","1","_GAS_" "ENTRY_DATE:","NULL" This is actually just a format I created to standardize from a more difficult and complex to read format. So I would set a loop up like: $aFile = _filereadtoarray... for $i = 1 to $aFile[0] $sEDICode = ParseCSV($aFile[$i], 0) if $sEDICode = "Tax_Charge" then do whatever $total = $total + ParseCSV($aFile[$i], 3) if $sEDICode = "Invoice_End" then do something else... next and so on. Hope that explains it. I will try to implement your suggestions to speed things up (currently it takes about 15-25 minutes for me to process and rewrite a 20,000 line file using this method). Thanks again for the help. -
Here is code I use for getting values out of a .CSV file (I am basing it on the .csv files made by OpenOffice.Org's Calc). It works but is rather slow (processing thousands of entries can take some time). I would appreciate any advise as to making it work faster. Also I am trying to use the UDF naming convention, point out any errors in that regards also. func ParseCSV($sCommaSeparatedValues, $iResultComma) Local $iCurrentComma = 0 Local $iLeft = 0 Local $sResult local $iRight = stringlen($sCommaSeparatedValues) local $iPosition local $cSeperator = "," local $cQuote = '"' local $iWithinQuotes = 0 ;This section finds the left bounds that we actually want $iPosition = 1 while($iCurrentComma < $iResultComma) if(stringmid($sCommaSeparatedValues, $iPosition, 1) = $cQuote) then if($iWithinQuotes = 0) Then $iWithinQuotes = 1 Else $iWithinQuotes = 0 EndIf EndIf if($iWithinQuotes = 0) Then if(stringmid($sCommaSeparatedValues,$iPosition,1) = $cSeperator) then $iCurrentComma = $iCurrentComma + 1 EndIf EndIf $iPosition = $iPosition + 1 if($iPosition > $iRight) Then return "NULL" EndIf WEnd ;This section gets the result $sResult = "" $iWithinQuotes = 0 while($iPosition < $iRight + 1) if(stringmid($sCommaSeparatedValues, $iPosition, 1) = $cQuote) Then $iPosition = $iPosition + 1 if($iWithinQuotes = 0) Then $iWithinQuotes = 1 Else $iWithinQuotes = 0 EndIf EndIf if($iWithinQuotes = 0) Then if(stringmid($sCommaSeparatedValues, $iPosition, 1) = $cSeperator) Then $iPosition = $iRight + 1 Else $sResult = $sResult & stringmid($sCommaSeparatedValues, $iPosition, 1) $iPosition = $iPosition + 1 EndIf Else $sResult = $sResult & stringmid($sCommaSeparatedValues, $iPosition, 1) $iPosition = $iPosition + 1 EndIf WEnd $sResult = stringstripws($sResult, 3) return $sResult EndFunc
-
If you can check where the file is being copied to, try something like ;Your copy command/function here $size = filegetsize($NEWfilename) sleep(1000) while(filegetsize($filename) <> $size) $size = filegetsize($filename) sleep(1000) wend Then when the file size stops changing, you know you are done copying.
-
Intermittent Clipput Issue
fsquirrelgpr replied to Mr. Crimson's topic in AutoIt General Help and Support
One small thing that might be causing an issue is not having a delay after you first send ^c to copy. I have ran into problems when I did not have a short delay after copying before reading the clipboard, though I am still an AutoIt Newbie and it could have been something else.... -
I would like to add code to a script that upon a real key press or mouseclick, runs a specified function (which will terminate the script and lock the PC (send win-L)). My initial idea was to use HotKeySet but after looking at it more closely, I do not think it would work. I looked at block input but again a user could hit alt-control-delete then have control. Basically I want to force anyone who might stumble across a computer running a script to be forced to enter the password to unlock the PC (or reboot it) before being able to do anything with the PC. I also want to use this functionality to protect passwords that are "sent" to web-sites (so the user could not just click on another window right before a password is sent to get it). Any suggestions on where to start or forum links to solutions to this problem?
-
I saw the posting with some code for navigating in Internet Explorer so thought I would post the functions I have been using for navigating in Firefox (entering information, navigating tables, activating windows, etc). These were cleaned up as not to be specific to the web-pages I use them with, but I might have missed a couple of references or broken a couple of functions by renaming variables and eliminating window names/usernames/passwords. I am sure there are better ways of doing many of these tasks but thought this might be useful for some, also remember I was (and still am) learning the language as I wrote these functions: #include-once ;This is an include file ; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x/NT (Mozilla Firefox) (Windows Server 2003) ; Author: Gregory Roby ; It assumes that Mozilla Firefox will be used (or Deer Park Alpha 2) ; Created originally 4/20/2005 by Gregory Roby, last modified 8/8/2005 ;Put the following line in any program that needs access to this file (assuming it has not moved) #include <file.au3> Global $standard_delay = 40 Global $short_delay = 1000 Global $medium_delay = 6000 Global $long_delay = 9000 global $win_activate_timeout = 75000; 75 seconds to activate a window global $current_position[2] global $run_function_on_exit_program = "none" ;$purple_button is the color of Buttons (dark purple) It varies a bit on different computers, use spread to find it global $purple_button = 132 global $purple_button_spread = 25 ;$firefox_green is the color of highlighted text when searched for using firefox global $firefox_green = 3725432 global $firefox_green_spread = 25 ; $blue_link is the blue color when a link is highlighted global $blue_link = 255 global $blue_link_spread = 15 ; $Deer_Park_Green is the green color of a the active link in Deer Park Alpha 2 (at least on my computer, not even sure what setting I changed to get it) global $deer_park_green = 1144610 global $deer_park_green_spread = 5 ;These are the names of Windows Global $win_mozilla = "Mozilla Firefox" Global $win_security = "Security Error" global $win_report = "IIPdfReport" global $win_print = "print" global $win_command = "c:\windows\system32\command.com" global $win_deer = "deer" Global $progress_file_path = "p:\networ~1\progress\" global $progress_file_name = "default.txt" global $mozilla_directory = "c:\program files\mozilla firefox\" ;$pixels_to_check is the number of pixels to scan on a line after moving right to reposition the mouse cursor to the ;same position, $pixel_row is the array that stores the color values of the pixels global $pixels_to_check = 225 global $pixel_row[1000] ;Color of Button When Mouse Overed (with our billing system) global $blue_button_mouseover = 3355545 global $blue_button_mouseover_spread = 25 ;these variables is set by calling max_coords() global $max_x global $max_y ;is the color of the dividing lines for the tables in Exception Manager global $grey_table = 9276813 global $grey_table_spread = 25 ; assumes the window needing the info entered is active, ;It attempts to search for the pixel color of the search string highlighed using Mozilla ;and enters the_info in the very next field func enter_info($the_info, $the_search_string, $optional_delay = 40) opt("sendkeydelay", $optional_delay) local $the_position[2] send("^f") send($the_search_string) $the_position = pixelsearch(0, 25,1280,1024,$firefox_green, $firefox_green_spread,3) mousemove($the_position[0], $the_position[1]) sleep($short_delay / 4) mouseclick("left") sleep($short_delay / 4) send("{tab}") opt("sendkeydelay", $optional_delay / 2) send ($the_info) opt("sendkeydelay", $standard_delay) EndFunc func open_command() run("c:\windows\system32\command.com", "") my_activate_window($win_command, "Could not open a command prompt.") EndFunc func run_command($the_command) Opt("SendKeyDelay", 10) send($the_command, 1) send("{enter}") sleep($short_delay / 4) Opt("SendKeyDelay", $standard_delay) EndFunc func close_command() send("exit{enter}") wait_for_window_to_close($win_command) EndFunc ;*************************************************************************************************** ********************* ;***********The following functions deal with navigating through tables (including scrolling right)*********** ;*************************************************************************************************** ********************* func next_box_right($boxes_right = 1) local $boxes_moved = 0 for $boxes_moved = 1 to $boxes_right local $reference_x = 0 local $had_to_move_right = 0 Do ;Always want to have a box to the right of the current box ;so First, go right until a line is found (will always happen unless there is something unaccounted for wrong) $current_position[0] = $current_position[0] + 1 mousemove($current_position[0], $current_position[1], 0) if($current_position[0] = $max_x) Then exit_program("When searching for the next_box_right, could not find the right hand side of the current box.") EndIf until(pixelgetcolor($current_position[0], $current_position[1]) = $grey_table) $reference_x = $current_position[0] ;Now you are at the next box to the right, but not sure if the right side of that box is on the screen yet, so ;do these steps to make sure: local $loop_problem = 0 $current_position[0] = $current_position[0] + 2 while(another_box_to_the_right($current_position[0], $current_position[1]) = 0) ;being here in the loop statement means there is not a right edge to the current box on the screen ;move mouse pointer left to the last grey line Do $current_position[0] = $current_position[0] - 1 until(pixelgetcolor($current_position[0], $current_position[1]) = $grey_table) ;now get some pixels to the left of this line so we can find where we were get_pixels_to_left($current_position[0], $current_position[1], $pixels_to_check) ;get_pixels_to_left are stored in the global array $pixel_row ;now actually move over to the right (hit right arrow key a few times) move_right() $loop_problem = $loop_problem + 1 if($loop_problem = 50) Then exit_program("Got stuck in the loop trying to find another box to the right (could not find one after 50 moves to the right).") EndIf sleep($short_delay) ;now set the x coordinate to be where it was before we cold not find another_box_to_the_right $current_position[0] = find_end_of_pixels($pixels_to_check) WEnd ;then move off the dividing line $current_position[0] = $current_position[0] + 3 Next EndFunc func find_end_of_pixels($number_of_pixels) local $temp_x = 0 local $current_x = 0 local $found_match = 1 Do $found_match = 1 for $temp_x = $current_x to $current_x + $pixels_to_check if not (pixelgetcolor($temp_x, $current_position[1]) = $pixel_row[$temp_x - $current_x]) Then $temp_x = $current_x + $pixels_to_check $found_match = 0 EndIf $temp_x = $temp_x + 1 Next $current_x = $current_x + 1 if($current_x = $max_x) Then exit_program("Could not find the pixel row after scrolling to the right") EndIf until $found_match = 1 $current_x = $temp_x + 4 return $current_x EndFunc func another_box_to_the_right($x_start, $y_position) Do $x_start = $x_start + 1 if($x_start = $max_x) Then return 0 EndIf until(pixelgetcolor($x_start, $y_position) = $grey_table) return 1 EndFunc func get_pixels_to_left($x_start, $y_position, $number_of_pixels) local $i local $temp_x = $x_start $temp_x = $x_start - $number_of_pixels for $i = 0 to $number_of_pixels - 1 $pixel_row[$i] = pixelgetcolor($temp_x, $y_position) $temp_x = $temp_x + 1 Next EndFunc func move_right() send("{right}") sleep($short_delay) EndFunc ;This function copies the contents of the current box. It also moves the mouse position to the beginning of the next box. ;Contents will be on the clipboard func copy_current_box() next_box_right() local $copy_temp_x = $current_position[0] Do $copy_temp_x = $copy_temp_x - 1 until(pixelgetcolor($copy_temp_x, $current_position[1]) = $grey_table) $copy_temp_x = $copy_temp_x - 3 mousemove($copy_temp_x, $current_position[1], 0) sleep($short_delay / 2) mousedown("left") Do $copy_temp_x = $copy_temp_x - 1 Until(pixelgetcolor($copy_temp_x, $current_position[1]) = $grey_table) $copy_temp_x = $copy_temp_x - 3 mousemove($copy_temp_x, $current_position[1], 0) sleep($short_delay / 2) mouseup("left") sleep($short_delay / 2) send("^c") sleep($short_delay / 2) mousemove($current_position[0], $current_position[1], 0) EndFunc ;*************************************************************************************************** ********************* ;***********The preceding functions deal with navigating through tables (including scrolling right)*********** ;*************************************************************************************************** ********************* ;This function waits until the hourglass goes away func wait_until_done($max_wait = 120000) local $counter = 0 while(mousegetcursor() = 1) $counter = $counter + $short_delay sleep($short_delay) if($counter > $max_wait) Then exit_program("Stuck in wait until done loop, exited after " & string($counter) & "ms, mousegetcursor is: " & string(mousegetcursor())) EndIf WEnd sleep($short_delay / 4) endfunc ;This function will close all opened mozilla windows (used by this include file) func cleanup() winclose($win_command) winclose($win_deer) EndFunc ; This function attempts to activate a window. It will exit the script if the window cannot be activated. ; It keeps trying until $win_activate_timeout is reached func my_activate_window($win_name, $fail_reason, $maximize = "yes") local $seconds = 0 ;try to activate the window for up to $win_activate_timeout then fail Do winactivate($win_name) if(winactive($win_name)) then $seconds = $win_activate_timeout if($maximize = "yes") Then winsetstate($win_name, "", @SW_MAXIMIZE) EndIf EndIf sleep($short_delay / 2) $seconds = $seconds + ($short_delay / 2) until $seconds > $win_activate_timeout if(not winactive($win_name)) then exit_program($fail_reason) EndIf wait_until_done() EndFunc func max_coords() local $temp_pos[2] local $max_pos[2] $temp_pos = mousegetpos() mousemove(5000, 5000, 0) $max_pos = mousegetpos() mousemove($temp_pos[0], $temp_pos[1], 0) $max_x = $max_pos[0] $max_y = $max_pos[1] EndFunc func wait_for_window_to_close($window_name) winactivate($window_name) Do sleep($short_delay) until(not winactive($window_name)) EndFunc func reset_current_position() $current_position[0] = 0 $current_position[1] = 0 endfunc ;Exit program uses a string variable ;It gives a slightly more user friendly exit then otherwise might occur. ;The goal is to exit if it is detected that a script is not working rather then have it do random stuff on the ;screen for extended periods of time ;It also checks the global variable $run_function_on_exit_program, if it is set it will call the selected function instead of exiting ;This is used for a script to continue working even when an error is encountered (set to none by default) func exit_program($exit_reason) if($run_function_on_exit_program = "none") Then cleanup() if(not ($exit_reason = "exit")) Then $exit_reason = "The problem was related to: " & $exit_reason msgbox(1,"Script Aborted", $exit_reason) exit 0 EndIf EndIf call($run_function_on_exit_program) exit 0 EndFunc ;between_commas will return the the information between which_comma and which_comma + 1 ;for example, if which_comma = 0, it will return everything before the first comma ;it needs a string and which comma (integer) as arguments func between_commas($the_string, $which_comma) Local $current_comma = 0 Local $left_bound = 0 Local $temp_string local $right_bound = stringlen($the_string) local $character_position local $separator = "," local $quote_character = '"' local $in_quotes = 0 ;This section finds the left bounds that we actually want $character_position = 0 while($current_comma < $which_comma) if(stringmid($the_string, $character_position, 1) = $quote_character) then if($in_quotes = 0) Then $in_quotes = 1 Else $in_quotes = 0 EndIf EndIf if($in_quotes = 0) Then if(stringmid($the_string,$character_position,1) = $separator) then $current_comma = $current_comma + 1 EndIf EndIf $character_position = $character_position + 1 if($character_position > $right_bound) Then exit_program("function betwen_commas is trying to find comma: " & $which_comma & " but only found: " & $current_comma & " commas. Exceeded length of array which was " & $right_bound & "The string is " & $the_string) EndIf WEnd $temp_string = "" $in_quotes = 0 while($character_position < $right_bound + 1) if(stringmid($the_string, $character_position, 1) = $quote_character) Then $character_position = $character_position + 1 if($in_quotes = 0) Then $in_quotes = 1 Else $in_quotes = 0 EndIf EndIf if($in_quotes = 0) Then if(stringmid($the_string, $character_position, 1) = $separator) Then $character_position = $right_bound + 1 Else $temp_string = $temp_string & stringmid($the_string, $character_position, 1) $character_position = $character_position + 1 EndIf Else $temp_string = $temp_string & stringmid($the_string, $character_position, 1) $character_position = $character_position + 1 EndIf WEnd return $temp_string EndFunc ;This function will convert any "year" numbers for 1990-2090 to a 2 digit year by stripping off the left two characters ;it uses a brute force approach func convert_date($the_date) local $date_conversion_counter local $temp_date = $the_date for $date_conversion_counter = 1990 to 2090 $temp_date = stringreplace(stringstripws(" " & $temp_date,8), stringstripws(" " & $date_conversion_counter, 8), stringright($date_conversion_counter, 2)) Next return $temp_date EndFunc ;This function makes sure that the specified folder exists, if not, it creates it ;only looks one folder deep so check each level func make_sure_exists($specified_folder) if(not fileexists($specified_folder)) Then open_command() run_command('md "' & $specified_folder & '"') close_command() EndIf EndFunc ;click on Found assumes the window needing the info entered is active, ;It attempts to search for the pixed color of the search string highlighed using Mozilla ;and clicks on whatever is highlighted ;flag is what flag (if any) to use for sending the search string func click_on_found($the_search_string, $x_offset = 0, $y_offset = 0, $flag = 0) opt("sendkeydelay", $standard_delay) local $the_position[2] send("^f") send($the_search_string, $flag) $the_position = pixelsearch(0, 25,1280,1024,$firefox_green, $firefox_green_spread,3) mousemove($the_position[0] + $x_offset, $the_position[1] + $y_offset) sleep($short_delay / 2) mouseclick("left") wait_until_done() sleep($short_delay / 2) EndFunc ;This function replaces the special "send" characters in a string with those characters in brackets ;and returns the result func string_simple($input_string) local $the_string = $input_string $the_string = stringreplace($the_string, "{", "{{}") $the_string = stringreplace($the_string, "}", "{}}") $the_string = stringreplace($the_string, "+", "{+}") $the_string = stringreplace($the_string, "^", "{^}") $the_string = stringreplace($the_String, "!", "{!}") $the_string = stringreplace($the_string, "#", "{#}") return $the_string EndFunc ;This function sets alternate window names for Deer Park (Mozilla Alpha) func alternate_deer_windows() Opt("SendKeyDelay", $standard_delay) ;5 milliseconds Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=... $win_mozilla = "Deer Park" $mozilla_directory = "c:\program files\Deer Park Alpha 2\" EndFunc ;This function does only some of the cleanup tasks so that windows which can be reused are reused to speed things up a bit func partial_cleanup() winclose($win_command) EndFunc ;This function adds a tick to the progress file (number 1) so its size can be checked to make sure progress is continuing without ;have to make complicated functions to see what a script is actually doing func add_tick_to_progress_file() $progress_file = fileopen($progress_file_path & $progress_file_name, 1) filewrite($progress_file, "1") fileclose($progress_file) EndFunc func get_progress_file_size() return(filegetsize($progress_file_path & $progress_file_name)) EndFunc ;This function removes the first entry from a file and puts it into the 2nd file func remove_first_entry($file_one_name, $file_two_name) local $single_line = "" local $counter local $error_file_as_array[25000] local $the_original_file _filereadtoarray($file_one_name, $error_file_as_array) ;This section writes everything back to the error file except for the 1st line sleep($short_delay / 2) $the_original_file = fileopen($file_one_name, 2) for $counter = 2 to $error_file_as_array[0] if(stringlen($error_file_as_array[$counter]) > 5) Then $error_file_as_array[$counter] = stringstripcr($error_file_as_array[$counter]) $error_file_as_array[$counter] = stringreplace($error_file_as_array[$counter], @LF, "") FileWriteline($the_original_file, $error_file_as_array[$counter]) EndIf Next fileclose($the_original_file) ;This section appends the log file with the first line from the other file (gets name from global variable $current_error_file) local $log_file $log_file = fileopen($file_two_name, 1) if(stringlen($error_file_as_array[1]) > 5) then $error_file_as_array[1] = stringstripcr($error_file_as_array[1]) $error_file_as_array[1] = stringreplace($error_file_as_array[1], @LF, "") FileWriteline($log_file, $error_file_as_array[1]) EndIf fileclose($log_file) EndFunc ;This function finds the left and right side of the $text_to_find ;and sets $left and $right = to them ($right is optional) func location_of_text_horizontal($text_to_find, $left, $right = 0) send("^f") send($text_to_find) local $temp_position[2] $temp_position = pixelsearch(0, 25,1600,1200,$firefox_green, $firefox_green_spread,3) $left = $temp_position[0] $right = $left + 250 Do $right[0] = $right[0] - 1 Until (pixelgetcolor($right, $temp_position[1]) = pixelgetcolor($left, $temp_position[1])) EndFunc ;This function finds the top and bottom of selected text and sets top and bottom to that location func location_of_text_vertical($text_to_find, $top, $bottom = 0) send("^f") send($text_to_find) local $temp_position[2] $temp_position = pixelsearch(0, 25,1600,1200,$firefox_green, $firefox_green_spread,3) $top = $temp_position[1] $bottom = $top + 250 Do $bottom = $bottom - 1 Until (pixelgetcolor($temp_position[0], $bottom) = pixelgetcolor($temp_position[0], $top)) EndFunc ;This function removes both @LF's and @CR's from a string, returning the result func no_lf_or_cr($the_string) local $new_string $new_string = stringstripcr($the_string) $new_string = stringreplace($new_string, @LF, "") return $new_string EndFunc
-
Parsing a Excel CSV-file into variables
fsquirrelgpr replied to GHGjelstad's topic in AutoIt General Help and Support
Here is a function I made to read fields from .csv files (after reading the file to an array), it is simple and only works on the most simple files, but change the "," to a ";" and it might get you started. exit_program is just a function to perform some cleanup if an error is detected. ;between_commas will return the the information between which_comma and which_comma + 1 ;for example, if which_comma = 0, it will return everything before the first comma ;it needs a string and which comma (integer) as arguments func between_commas($the_string, $which_comma) dim $current_comma = 0 dim $left_bound = 0 dim $temp_string dim $right_bound = stringlen($the_string) dim $character_position ;This section finds the left bounds that we actually want $character_position = 0 while($current_comma < $which_comma) if(stringmid($the_string,$character_position,1) = ",") then $current_comma = $current_comma + 1 EndIf $character_position = $character_position + 1 if($character_position > $right_bound) Then exit_program("function betwen_commas is trying to find comma: " & $which_comma & " but only found: " & $current_comma & " commas. Exceeded length of array which was " & $right_bound & ". Possibly a corrupt file or an error in the script.") EndIf WEnd $temp_string = " " while($character_position < $right_bound + 1) if(stringmid($the_string, $character_position, 1) = ",") Then $character_position = $right_bound + 1 Else $temp_string = $temp_string & stringmid($the_string, $character_position, 1) $character_position = $character_position + 1 EndIf WEnd return $temp_string EndFunc -
Below is a segment of code that I am trying to use to perform a set of actions on a large number of files. Some of the commands are from an include file I have made but should be self explanatory. Basically, the segment makes a directory list of all files names in a specific location which is piped to files.txt. The script then reads in each line of files.txt into an array called $the_pdf_files[100000]. With around 7,000 files, it takes about 5-10 minutes to read into the array. If possible, I would like it to take about 5-10 minutes to read in 50,000 or so file names. Any suggestions or pointers in the right direction? ;First do a dir /b >filelist.txt run_command("dir " & $pdf_location & "*.pdf /b >" & $pdf_location & "files.txt") msgbox(1, "Click ok", "Click ok when the command is finished.") $the_file = FileOpen($pdf_location & "files.txt",0) if($the_file = -1) Then exit_program("Could not open files.txt, which contains the list of .pdf files on d:\, generated by this script.") EndIf dim $count = 0 Do $the_pdf_files[$count] = filereadline($the_file, $count + 1) $count = $count + 1 until @error $count = $count - 2 ;meaning read lines until eof fileclose($the_file) filedelete($pdf_location & "files.txt")
-
Checking for Hourglass with Mozilla Firefox
fsquirrelgpr replied to fsquirrelgpr's topic in AutoIt General Help and Support
Thanks so much (especially for the quick reply), it works and the script runs so much faster without those unnecessary waits. Firefox puts mousegetcursor at 1 for some reason instead of 15 when it has an hourglass (for my application at least) but again it works great. -
I have a couple of scripts that automate some tasks using Firefox. The steps involve clicking on update on certain pages. After clicking on update, the browser has to wait for the page to update and reload (which depending on network load can take from 4-60 seconds, usually less then 30). I have the script setup with about a 30 second timeout currently, which obviously does not work all of the time and when it does work can cause unnecessary delays. Is there an easy way to see if the window is finished processing? Opening new windows I know I can wait until the Window exists and is active, but in this case the window is remaining the same, just being updated. Possibly is there a variable to see if the hourglass is active? Let me know any ideas... if I have to I will code it to look for Done in the lower left hand corner... though I think there must be a better way. Also on that topic, have there been any attempts to integrate OCR into AutoIT (so you can search for text anywhere on the screen and get its position)?