
tonedeaf
Active Members-
Posts
148 -
Joined
-
Last visited
Everything posted by tonedeaf
-
I've re-posted the code, I forgot to update the forum it when I was checking for some incompatibilities between IE, jQuery and AutoIt. However, I think I stand a better chance if others users also try it and figure out why some jQuery DOM Manipulation functions won't work.
-
Update (22-Sep-08): Updated _IEPageLoadWait() function to check for document readyState. Updated _insertjQuery() function to define default location of jQuery.js and call _IEPageLoadWait()
-
I use AutoIt exclusively nowdays for web automation and found myself repeatedly using Internet Explorer methods document.getElementById(), document.getElementsByTagName(), then testing the elements returned for some conditions (using a loop) and extracting the data. With jQuery becoming the de-facto DOM Selector javascript library, I wondered if it was possible to "insert" jQuery into an IE page, then calling the rich jQuery API to select DOM elements. This would reduce the no. of lines in my AutoIt script drastically. One option is to use Dale Holm's Internet Explorer Automation Library, which comes with AutoIt. But it doesn't offer the feature rich API like jQuery. [** Dale is working on also adding support for jQuery in IE Automation, I hope he can help resolve some of the issues in DOM Manipulation using jQuery **] Download the latest jQuery library: http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js Rename it to "jquery.js" and save it in the same folder with the script below. Opt('MustDeclareVars', 1) Local $objCOMError, $objAppIE, $jQuery $objCOMError = ObjEvent("AutoIt.Error", "_COMErrorHandler") $objAppIE = ObjCreate("InternetExplorer.Application") $objAppIE.visible = True _GetFeaturedGoogleVideo($objAppIE) Func _GetFeaturedGoogleVideo($objAppIE) $objAppIE.navigate('http://video.google.com') $jQuery = _insertjQuery($objAppIE) ; Testing DOM selection functions. All DOM selection functions seem to work! ConsoleWrite('Featured Video: ' & $jQuery('table[class=hot_videos_body] div[class=title]').get(0).innerText & @LF) ConsoleWrite('Direct Link: ' & $jQuery('table[class=hot_videos_body] a[id=hs_title_link]').get(0).getAttribute('href') & @LF) ; Testing some DOM manipulation functions, some work and the others don't. Don't know why $jQuery("<p>What's Cooking!</p>").appendTo('body'); works $jQuery('body').hide(); doesn't work :( EndFunc Func _insertjQuery($objAppIE) Local $objWindow, $objHead, $objScript _IEPageLoadWait($objAppIE) $objWindow = $objAppIE.document.parentWindow $objHead = $objAppIE.document.getElementsByTagName('head').item(0) If Not(IsObj($objwindow.jQuery)) Then $objScript = $objAppIE.document.createElement('script') $objScript.type = 'text/javascript' $objScript.defer = 'defer' $objScript.text = FileRead(@ScriptDir & '\jquery.js') $objHead.appendChild($objScript) While Not(IsObj($objwindow.jQuery)) Sleep(100) WEnd $objwindow.jQuery.noConflict() EndIf Return $objwindow.jQuery EndFunc Func _IEPageLoadWait($objAppIE) Do Sleep(100) Until ($objAppIE.readyState = 'complete' Or $objAppIE.readyState = 4) Do Sleep(100) Until ($objAppIE.document.readyState = 'complete' Or $objAppIE.document.readyState = 4) EndFunc Func _COMErrorHandler() Switch $objCOMError.number Case -2147352570 Return 0 Case Else ; Don't use central errorhandler MsgBox(8240, "Automation Error", "Unhandled COM Automation Error." & @CRLF & @CRLF & _ "This operation resulted in an unhandled error." & @CRLF & @CRLF & _ "Technical Information: " & @CRLF & _ "Error Number: " & $objCOMError.number & @CRLF & _ "Error Description: " & $objCOMError.winDescription & @CRLF & _ "Line Number: " & $objCOMError.scriptLine & @CRLF & @CRLF & _ "Contact technical support for furthur help.") Exit EndSwitch EndFunc Update (20-Apr-09): Improved the jQuery injection routine, now uses a local file instead of linking to Google CDN network. The routine checks if jQuery is already being used by the website, and skips injection is if it does. Also, uses the jQuery.noConflict() to avoid problems with existing javascript libraries used on the web page. Update (30-Sep-08): Identified some issues with jQuery wrapped sets methods not working correctly when invoked from AutoIT. the DOM selector methods work but some DOM manipulation methods don't work when called from within AutoIT. Investigating, will post updated code as soon as I resolve the issue. The issue may be with the AutoIT COM translation of jQuery javascript objects. Update (22-Sep-08): Updated _IEPageLoadWait() function to check for document readyState. Updated _insertjQuery() function to define default location of jQuery.js and call _IEPageLoadWait()
-
Larry, If you don't want to install a service (using sc or psexec), how about using an existing service of windows to launch your process under SYSTEM account? The Schedule service exists in all windows versions and runs a process under SYSTEM account. Use the command line interface (AT.EXE) of Schedule service to run a process interactively or in background with SYSTEM priviledges. Just schedule a command to run one-minute ahead of the current time (in 24-hr format) eg. AT 17:10 /interactive "NOTEPAD.EXE"and the process gets launched at the scheduled time with SYSTEM priviledges. Surprisingly, I've seen many 2000/XP system guest accounts having access to the AT command.
-
I found a C# version of this hack on the internet. Didn't take me long to convert it to an AutoIt script Change $strPrinterIP value to Network IP Address of the printer. Some printers have an option to print their configuration, look for the IP Address under TCP/IP. Also, check Printer properties in Printers & Faxes in Control Panel, you can find the IP Address in the Ports Tab. ; Modify the Network Printer IP address and the message to display on the LCD screen ; Make sure the message is short enough to fit on the printer display $strPrinterIP = "10.30.210.40" $strMessage = "INSERT COIN" TCPStartUp() $socPrinter = TCPConnect($strPrinterIP, 9100) If $socPrinter = -1 Then Exit $strCommand = Chr(27) & Chr(27) & "%-12345X@PJL RDYMSG DISPLAY = " & Chr(34) & $strMessage & Chr(34) & @LF & Chr(27) & "%-12345X" & @LF TCPSend($socPrinter, $strCommand) Results on my company printer It'll also work on printers which accept PCL/PJL commands. My success rate is 100% on all the printers. Some more examples: BUZZ OFF STEP AWAY SET TO STUN PAT EATS MICE GO AWAY NEED MORE SPACE POUR ME A DRINK IN DISTRESS FEED ME RADIATION LEAK NICE SHIRT! HANDS UP PRESS MY BUTTONS INSERT DISK LOOKS LIKE RAIN BUY ME LUNCH TAKE A BREAK INSERT QUARTER NO PRINT FOR YOU NICE HAIR NEED A MINT?
-
@stealthf117jm This was just a quick app to test the list view images when they were first introduced (way back) in v3.1.1.48 I don't know whether this would still work with the current release v3.2 Feel free to modify and use the code in your applications.
-
Web-based AutoIt! - New with AuCGI!
tonedeaf replied to theguy0000's topic in AutoIt Example Scripts
@theguy Really creative! How did you guess that ConsoleWrite() would send output to the Web page. I could really use this for my DHTML stuff. Thanks -
Check out this demo of TTS Voices by Loquendo:http://actor.loquendo.com/actordemo/default.asp They are the absolute best in my opinion. To try them out for 30 days you can download them from: http://www.qualilife.com/products/index.cfm?id=218 After you install them they'll be available in the Voice Selection in Speech Properties.
-
DllCreateStruct with sub-structure array
tonedeaf replied to cojms1's topic in AutoIt General Help and Support
@cojms1 Thanks for posting the working code. -
Loading (image) resource from file
tonedeaf replied to Holger's topic in AutoIt General Help and Support
Holger, I tried sometime back to modify Larry's version of LoadImage function to work for Loading images from resources. And I partially succeeded. I don't know whether its of any use to you, but here is how it works: I didn't know how to "get" a resource from a file on disk (like shell32.dll), instead this script can get a resource from "its own compiled executable file". To add resources, I simply used resource hacker to add bmp images to AUTOITSC.BIN and when you compile the script, those bmp images get added to the compiled executable. The function that loads the resource images from the executable is: Func LoadImageFromResource(ByRef $hWin, ByRef $nID, $sRes) Local Const $GWL_HINSTANCE = -6 Local Const $IMAGE_BITMAP = 0 Local $ret[4], $hInst, $hBmp, $phWnd, $dc, $dc1, $old $hInst = DllCall("user32.dll", "int", "GetWindowLong", "hWnd", $hWin, "int", $GWL_HINSTANCE) $hBmp = DllCall("user32.dll", "hwnd", "LoadImage", "hwnd", $hInst[0], "str", $sRes, _ "int", $IMAGE_BITMAP, "int", 0, "int", 0, "int", 0) $phWnd = DLLCall("user32.dll","hwnd","GetDlgItem","hwnd",$hWin,"int",$nID) $dc = DllCall("user32.dll","int","GetDC","hwnd",$phWnd[0]) $dc1 = DLLCall("gdi32.dll","int","CreateCompatibleDC","int",$dc[0]) $old = DLLCall("gdi32.dll","hwnd","SelectObject","int",$dc1[0],"hwnd",$hBmp[0]) $ret[0] = $dc[0] $ret[1] = $dc1[0] $ret[2] = $hBmp[0] $ret[3] = $old[0] Return $ret EndFuncwhere $hWnd = handle of the AutoIt Gui $nID = handle of the control which displays the picture (like a picture box). $sRes = name of the resource in the executable. Download from here for the complete working example: http://www.mytempdir.com/784085 This zip file has a folder "RES" which has a copy of AUTOITSC.BIN modified to add a resource image called "BAR". This image gets loaded by the script ONLY WHEN IT IS COMPILED. Right-Click on the LoadImage.au3 script and choose "Compile with Options". This ensures that the modified version of AUTOITSC.BIN is used to compile the script. Here's how it would look if you did everything correctly: Sorry, for this obsure example, but this is the only way its working. If you can find a way to load resources even from static DLLs on disk, I would be very thankful for an example. Hope this is useful. Thanks, Tonedeaf -
Is it possible to track window resolution changes?
tonedeaf replied to Sreenath's topic in AutoIt General Help and Support
@Sreenath There may be other better ways of achieving what you want (using ControlClick functions rather than MouseMove), but if you want to change the screen resolution, look here: http://www.autoitscript.com/forum/index.ph...ost&p=77196 -
VB Code: For Each objPrinter in colInstalledPrinters Wscript.Echo "Printer " & objprinter.Name & " is not responding." Next would convert to: For $objPrinter in $colInstalledPrinters Msgbox(0, "", "Printer " & $objPrinter.Name & " is not responding.") Next
-
I can guess what this script does, but just for the sake of troubleshooting. Replace this code: MsgBox(1, "Auto-Heal", "F5 - 15 | F6 - 30 | F7 - 45 | F8 - 1MINUTE | F9 - 1.15 | F10 - 1.30 | F11 - 1.45 | F12 - 2MINUTES | NUMPAD0 - STOP ALL | NUMPAD1 - LEFTCLIC |K| NUMPAD2 - RIGHTCLICK | NUMPAD3 - AUTOLOOT | Made By MJB Crew | NUMPAD0 StopAll NUMPAD5, Terminate ALL | NUMPAD1 LeftClick |NUMPAD2 RightClick |NUMPAD3 AutoLoot |" HotKeySet("{F5}", "FFFFF") HotKeySet("{F6}", "FFFFFF") HotKeySet("{F7}", "FFFFFFF") HotKeySet("{F8}", "FFFFFFFF") HotKeySet("{F9}", "FFFFFFFFF") HotKeySet("{F10}", "FFFFFFFFFF") HotKeySet("{F11}", "FFFFFFFFFFF") HotKeySet("{F11}", "FFFFFFFFFFFF") HotKeySet("{NUMPAD0}", "StopAll") HotKeySet("{NUMPAD5}", "Terminate") HotKeySet("{NUMPAD1}", "LeftClick") HotKeySet("{NUMPAD2}", "RightClick") HotKeySet("{NUMPAD3}", "AutoLoot") TrayTip("MADE BY MJB CREW )", "Go to MPC Forums , for more updates.", 3, 2) with this MsgBox(0, "Auto-Heal", "F5 - 15 | F6 - 30 | F7 - 45 | F8 - 1MINUTE | F9 - 1.15 | F10 - 1.30 | F11 - 1.45 | F12 - 2MINUTES | NUMPAD0 - STOP ALL | NUMPAD1 - LEFTCLIC |K| NUMPAD2 - RIGHTCLICK | NUMPAD3 - AUTOLOOT | Made By MJB Crew | NUMPAD0 StopAll NUMPAD5, Terminate ALL | NUMPAD1 LeftClick |NUMPAD2 RightClick |NUMPAD3 AutoLoot |", "Go to MPC Forums , for more updates.") HotKeySet("{F5}", "FFFFF") HotKeySet("{F6}", "FFFFFF") HotKeySet("{F7}", "FFFFFFF") HotKeySet("{F8}", "FFFFFFFF") HotKeySet("{F9}", "FFFFFFFFF") HotKeySet("{F10}", "FFFFFFFFFF") HotKeySet("{F11}", "FFFFFFFFFFF") HotKeySet("{F11}", "FFFFFFFFFFFF") HotKeySet("{NUMPAD0}", "StopAll") HotKeySet("{NUMPAD5}", "Terminate") HotKeySet("{NUMPAD1}", "LeftClick") HotKeySet("{NUMPAD2}", "RightClick") HotKeySet("{NUMPAD3}", "AutoLoot") Spend some time to understand the changes. AutoIt can be used for lots of other tasks too.
-
The reason why other languages have a LBound() function is they allow you to define even the first element of the array. Eg: In VB you can define an array with Dim A(2 To 100) Where the array starts from 2 and using A(1) would generate an error. In such conditions, having a LBound function is useful. In AutoIt, an array always starts from 0 and as such a LBound() function is not required.
-
Script for all database connections...
tonedeaf replied to Raestlin's topic in AutoIt Example Scripts
@Raestlin Your script was very useful. It saved me a lot of time figuring out the database connections. Thanks for the working example. -
Listview/gui Number Of Records Limitation :/
tonedeaf replied to flash44's topic in AutoIt GUI Help and Support
Can you post an example of of a TVM_xxxx msg. I really want to manipulate list view items (change color, setting icon) without knowing their ControlIDs. Thanks -
Typical posts in the AutoIt 1-2-3 topic. How to use examiner? Examiner..... Examiner..... Examiner..... Examiner..... {Huh} Examiner..... Examiner..... Hey! where is my original post gone!.... Examiner..... Examiner..... Examiner..... Examiner..... Its three pages backwards. Examiner..... Examiner..... Examiner..... Examiner..... Examiner..... Examiner..... Examiner..... Examiner.....
-
I don't think there's any problem with populating a treeview with arrays of many dimensions. You can include the snippet in a code tag to make it easier to read. I noticed that you're manually incrementing the For loop variables: i = i + 1 j = j + 1 k = k + 1 l = l + 1 m = m + 1 When using a FOR loop, the variable initialized at the beginning of the for loop is automatically incremented when you specify "NEXT"
-
Read state or data of a control. GUICtrlRead ( controlID ) You're using GuiCtrlRead for $currentslot and you've to use the same for the checkbox($available).
-
I guess you're trying to access the value from the next cell to the right. So, if the value in $a_ArrayAnswer is "$B$3" then you want to read "$C$3". This code snippet will advance the cell column by one. Rest of the job is to simply read the value. #include<ExcelCOM.au3> $ReadXLPath = @ScriptDir&"\bin\USD_Configuration_Items.xls" $valu = "BACK UP UNIT" $s_FoundList=_XLSearch($ReadXLPath,1,$valu,0) if $s_FoundList<> "Nothing" then $a_ArrayAnswer=StringSplit($s_FoundList,"|") _ArrayDisplay($a_ArrayAnswer,"test window") For $i = 0 to UBound($a_ArrayAnswer) - 1 $sNextCellToTheRight = "$" & Chr(Asc(StringMid($a_ArrayAnswer[$i], 2, 1)) + 1) & "$" & StringRight($a_ArrayAnswer[$i], 1) ; Read the $sNextCellToTheRight from the excel sheet ;---------<Your code goes here>--------------- Next ; run("Notepad.exe") ; Sleep(2000) ; send($s_FoundList);this will give cell locations _XLExit($ReadXLPath);, "NOSave") Else msgbox(0,"","$s_FoundList="&$s_FoundList) EndIf
-
Can Listview Checkboxes Be Disabled
tonedeaf replied to JerryD's topic in AutoIt GUI Help and Support
If there's a solution to do that in AutoIt, I would be very interested. BTW: Microsoft says that its not easy: http://groups.google.co.in/group/microsoft...13409f631f11bbb -
Here's another example:
-
How To Hide Window Title Bar?
tonedeaf replied to Diarazad's topic in AutoIt General Help and Support
If you don't want the title bar, you can use any of these two styles in GUICreate() > $WS_POPUP - Creates a window without a title bar, and without border. > $WS_POPUPWINDOW - Creates a windows without a title bar but with a border. -
Error: Variable Must Be Of Type "object"
tonedeaf replied to michael's topic in AutoIt General Help and Support
It would be possible that WMI queries are not working on the machines due to reasons like permissions, unavailable services, security settings etc. It would be useful if you can post the complete script here. However if you don't want your scripts to crash in case the WMI queries could not be executed, then use the IsObj() function to check if the variable is a valid object before calling any functions from it. -
Looks like the Examiner has become an advanced member. Great to see the official AutoIt teacher getting recognition. EDIT: Grammer