Leaderboard
Popular Content
Showing content with the highest reputation on 07/20/2014 in all areas
-
In the last versions of Windows, it has been difficult to automate Windows Explorer. But there are many examples of code like this to extract the selected items: ; Windows Explorer on XP, Vista, 7, 8 $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then Exit ; Shell object $oShell = ObjCreate( "Shell.Application" ) ; Find window For $oWindow In $oShell.Windows() If $oWindow.HWND() = $hExplorer Then ExitLoop Next ; Selected items For $oItem In $oWindow.Document.SelectedItems() ConsoleWrite( $oItem.Path() & @CRLF ) Next It's possible to create these objects with ObjCreateInterface. More precisely, create an IShellBrowser interface for the top level browser of an open Windows Explorer. Plan and code This is the plan: Create an IShellWindows interface to get a list of shell windows Get an IWebBrowserApp object for each window. This is done in two steps: Get an IDispatch object for the window Get the IWebBrowserApp interface Identify the proper shell window with get_HWND of IWebBrowserApp Get an IServiceProvider interface with QueryInterface of IWebBrowserApp Get the IShellBrowser interface with QueryService of IServiceProvider This is the code: Func GetIShellBrowser( $hExplorer ) ; IShellWindows interface Local $pIShellWindows, $oIShellWindows CoCreateInstance( $tCLSID_ShellWindows, $NULL, $CLSCTX_ALL, $tRIID_IShellWindows, $pIShellWindows ) $oIShellWindows = ObjCreateInterface( $pIShellWindows, $sIID_IShellWindows, $dtag_IShellWindows ) ; Number of shell windows Local $iWindows $oIShellWindows.get_Count( $iWindows ) ; Get an IWebBrowserApp object for each window ; This is done in two steps: ; 1. Get an IDispatch object for the window ; 2. Get the IWebBrowserApp interface ; Check if it's the right window Local $pIDispatch, $oIDispatch Local $pIWebBrowserApp, $oIWebBrowserApp, $hWnd For $i = 0 To $iWindows - 1 $oIShellWindows.Item( $i, $pIDispatch ) If $pIDispatch Then $oIDispatch = ObjCreateInterface( $pIDispatch, $sIID_IDispatch, $dtag_IDispatch ) $oIDispatch.QueryInterface( $tRIID_IWebBrowserApp, $pIWebBrowserApp ) If $pIWebBrowserApp Then $oIWebBrowserApp = ObjCreateInterface( $pIWebBrowserApp, $sIID_IWebBrowserApp, $dtag_IWebBrowserApp ) $oIWebBrowserApp.get_HWND( $hWnd ) If $hWnd = $hExplorer Then ExitLoop EndIf EndIf Next ; IServiceProvider interface Local $pIServiceProvider, $oIServiceProvider $oIWebBrowserApp.QueryInterface( $tRIID_IServiceProvider, $pIServiceProvider ) $oIServiceProvider = ObjCreateInterface( $pIServiceProvider, $sIID_IServiceProvider, $dtag_IServiceProvider ) ; IShellBrowser interface Local $pIShellBrowser $oIServiceProvider.QueryService( $tRIID_STopLevelBrowser, $tRIID_IShellBrowser, $pIShellBrowser ) $oIShellBrowser = ObjCreateInterface( $pIShellBrowser, $sIID_IShellBrowser, $dtag_IShellBrowser ) EndFunc Now it's easy to create the shell interfaces. The main interfaces are: Func GetShellInterfaces() Local $pIFolderView, $pIFolderView2, $pIPersistFolder2, $pIShellFolder, $pPidlFolder, $pPidlRel, $i = 0 ; IShellView interface $oIShellBrowser.QueryActiveShellView( $pIShellView ) $oIShellView = ObjCreateInterface( $pIShellView, $sIID_IShellView, $dtag_IShellView ) ; IFolderView interface $oIShellView.QueryInterface( $tRIID_IFolderView, $pIFolderView ) $oIFolderView = ObjCreateInterface( $pIFolderView, $sIID_IFolderView, $dtag_IFolderView ) If @OSVersion <> "WIN_XP" Then ; IFolderView2 interface (Vista and later) $oIShellView.QueryInterface( $tRIID_IFolderView2, $pIFolderView2 ) $oIFolderView2 = ObjCreateInterface( $pIFolderView2, $sIID_IFolderView2, $dtag_IFolderView2 ) EndIf ; IPersistFolder2 interface $oIFolderView.GetFolder( $tRIID_IPersistFolder2, $pIPersistFolder2 ) $oIPersistFolder2 = ObjCreateInterface( $pIPersistFolder2, $sIID_IPersistFolder2, $dtag_IPersistFolder2 ) $oIPersistFolder2.GetCurFolder( $pPidlFolder ) ; IShellFolder interface If ILIsEqual( $pPidlFolder, $pPidlAbsDesktop ) Then SHGetDesktopFolder( $pIShellFolder ) Else Local $pIParentFolder, $oIParentFolder, $pPidlRel SHBindToParent( $pPidlFolder, DllStructGetPtr( $tRIID_IShellFolder ), $pIParentFolder, $pPidlRel ) $oIParentFolder = ObjCreateInterface( $pIParentFolder, $sIID_IShellFolder, $dtag_IShellFolder ) $oIParentFolder.BindToObject( $pPidlRel, $NULL, $tRIID_IShellFolder, $pIShellFolder ) EndIf $oIShellFolder = ObjCreateInterface( $pIShellFolder, $sIID_IShellFolder, $dtag_IShellFolder ) ; Free memory used by $pPidlFolder _WinAPI_CoTaskMemFree( $pPidlFolder ) ; Wait for Explorer to refresh $pPidlRel = GetFocusedItem() While Not $pPidlRel And $i < 10 Sleep( 25 ) $pPidlRel = GetFocusedItem() $i += 1 WEnd ; Free memory used by $pPidlRel If $pPidlRel Then _ _WinAPI_CoTaskMemFree( $pPidlRel ) EndFunc Features The methods of the interfaces supports the following features: You can handle items in Windows Explorer: Get current folder, get all items, get/set selected items and get/set focused item. A selected file is opened by executing the InvokeCommand for the default item in the context menu. You can browse to a specific folder or a parent/child folder. You can set icon view mode. Functions AutomatingWindowsExplorer.au3 contains the two functions above. And it contains a number of functions to implement the features: GetCurrentFolder SetCurrentFolder CountItems GetItems GetFiles GetFolders GetPidls GetFocusedItem SetFocusedItem SetSelectedItem GetIconView SetIconView When the interfaces are created, the functions can be implemented with a few lines of code. This is the code for GetCurrentFolder and SetCurrentFolder: Func GetCurrentFolder() Local $pPidlAbs $oIPersistFolder2.GetCurFolder( $pPidlAbs ) Return $pPidlAbs EndFunc ; After this command $oIShellBrowser is the only valid interface object. To ; be able to use the other interfaces you must execute GetShellInterfaces(). Func SetCurrentFolder( $pPidl, $fFlag ) $oIShellBrowser.BrowseObject( $pPidl, BitOR( $SBSP_DEFBROWSER, $fFlag ) ) EndFunc For examples search the functions in Example.au3 and Example*.au3. Depending on parameters most functions can return PIDLs. Some functions return only PIDLs. In these cases you must free memory (_WinAPI_CoTaskMemFree) used by the PIDLs, when you have finished using the PIDLs. There are many more methods that are not implemented in these functions, and there are available interfaces that have not been created. Example Example.au3 demonstrates the features. Example folder contains scripts with functions used in the example. It's important that there is consistency between the interfaces, and the current folder in Windows Explorer. If the GUI loses and gets focus, it's checked if the current folder is changed. In that case the interfaces are updated to match the new folder. This is a picture of the GUI: Items and selected items are shown with _ArrayDisplay. The number of rows in the listview to the right is limited to 100. The listview can only be used for the buttons in the lower right group. The buttons in the lower left group are disabled, if there are more than 100 items in the folder. There is also a listview on the second tab item. It's limited to 100 rows, and can only be used for the Child folder button. You can also double click a child folder in the listview, to browse to this folder. Control Panel The example does not work for the Control Panel. The reason is that the child windows which are created for the Control Panel, are different from the child windows which are created for other folders. You can verify that with the UI Automation framework. Zipfile Example - include files used in example Includes - include files used for Automating Windows Explorer Example.au3 - Example For AutoIt 3.3.10 and later. Testet on Windows XP 32 bit and Windows 7 32/64 bit. Automating Windows Explorer.7z Examples in posts below Post 7 is a collection of small examples. Post 15 shows how to automate a search with UI Automation code. Post 31 shows how to execute a function on a double-click in empty space of the right pane window (the listview). The code contains UI Automation code. Post 38 is UI Automation code to make a selected item visible by scrolling the listview up or down.2 points
-
I asked this question back in >December 2012 and just stumbled across the answer when I was looking at monitoring when a titlebar text changes. Funny how things seem so simple when you know how. #include <ScrollbarConstants.au3> #include <WinAPISys.au3> Global $hEventProc = DllCallbackRegister('_EventProc', 'none', 'ptr;dword;hwnd;long;long;dword;dword') Global $hEventHook = _WinAPI_SetWinEventHook($EVENT_OBJECT_VALUECHANGE, $EVENT_OBJECT_VALUECHANGE, DllCallbackGetPtr($hEventProc), ProcessExists('SciTE.exe')) Global $hSciTEEdit = ControlGetHandle(WinGetHandle('[CLASS:SciTEWindow]'), '', '[CLASS:Scintilla; INSTANCE:1]') Sleep(10000) Func OnAutoItExit() _WinAPI_UnhookWinEvent($hEventHook) DllCallbackFree($hEventProc) EndFunc ;==>OnAutoItExit Func _EventProc($hEventHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iThreadID, $iEventTime) #forceref $hEventHook, $iObjectID, $iChildID, $iThreadID, $iEventTime ; http://msdn.microsoft.com/en-us/library/windows/desktop/dd373606(v=vs.85).aspx If $hWnd = $hSciTEEdit And $iObjectID = $OBJID_VSCROLL Then ; Monitor only if the hWnd matches the SciTE edit handle and the object id is a vertical scrollbar. Switch $iEvent Case $EVENT_OBJECT_VALUECHANGE ConsoleWrite('SciTE scrollbar move.' & @CRLF) EndSwitch EndIf EndFunc ;==>_EventProc2 points
-
I wrestled with this one for a few days, but finally got the basics figured out. You need a microphone plugged into your computer (not a USB mic or you'll have to configure the app for it.) If you don't have SAPI, you can download 5.1 here. Try the script before, it seems SAPI gets distributed with most Vista and 7 versions. This listens to what you say into the mic, runs it through the windows speech recognition engine, and outputs the results to console. Results improve the more you train the system. I'm getting decent accuracy after about an hour of training. This uses a localized speech recognition engine, meaning that it's not subject to the Vista/7 built in Speech Recognition tool. This means you can add it into your app for your own commands, and it won't capture the basic Speech commands. There are ways of specifying grammars, utilizing the training tools, and other intricacies I haven't got to yet. Thanks to ProgAndy, cyberZeroCool, seangriffin, and all the others who've done SAPI work, you guys have blazed the trails for some very fun stuff. Global $h_Context = ObjCreate("SAPI.SpInProcRecoContext") Global $h_Recognizer = $h_Context.Recognizer Global $h_Grammar = $h_Context.CreateGrammar(1) $h_Grammar.Dictationload $h_Grammar.DictationSetState(1) ;Create a token for the default audio input device and set it Global $h_Category = ObjCreate("SAPI.SpObjectTokenCategory") $h_Category.SetId("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput\TokenEnums\MMAudioIn\") Global $h_Token = ObjCreate("SAPI.SpObjectToken") $h_Token.SetId("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput\TokenEnums\MMAudioIn\") $h_Recognizer.AudioInput = $h_Token Global $i_ObjInitialized = 0 Global $h_ObjectEvents = ObjEvent($h_Context, "SpRecEvent_") If @error Then ConsoleWrite("ObjEvent error: " & @error & @CRLF) $i_ObjInitialized = 0 Else ConsoleWrite("ObjEvent created Successfully!" & @CRLF) $i_ObjInitialized = 1 EndIf While $i_ObjInitialized Sleep(5000) ;Allow the Audio In to finalize processing on the last 5 second capture $h_Context.Pause ;Resume audio in processing $h_Context.Resume ;Reset event function allocation (what is this? I think its garbage collection or something, needs clarification) $h_ObjectEvents = ObjEvent($h_Context, "SpRecEvent_") WEnd Func SpRecEvent_Hypothesis($StreamNumber, $StreamPosition, $Result) ConsoleWrite("Hypothesis(): Hypothized text is: " & $Result.PhraseInfo.GetText & @CRLF) EndFunc ;==>SpRecEvent_Hypothesis Func SpRecEvent_Recognition($StreamNumber, $StreamPosition, $RecognitionType, $Result) ConsoleWrite($RecognitionType & "||" & $Result.PhraseInfo.GetText & @CRLF) EndFunc ;==>SpRecEvent_Recognition Func SpRecEvent_SoundStart($StreamNumber, $StreamPosition) ConsoleWrite("Sound Started" & @CRLF) EndFunc ;==>SpRecEvent_SoundStart Func SpRecEvent_SoundEnd($StreamNumber, $StreamPosition) ConsoleWrite("Sound Ended" & @CRLF) EndFunc ;==>SpRecEvent_SoundEnd The SoundEnd event doesn't appear to work. Everything else functions as intended. In order to use this, you have to parse completed phrases from the input. Don't worry about the Sleep(5000), that doesn't interfere with the operation of the recognition. That's just there to separate the sound input into manageable chunks. It's not in UDF format, but should be very easy to adapt into your projects. A hypothesis is the engine's best guess as to what is being said. A recognition is a finalized hypothesis. After a recognition, any new input will be hypothesized until discarded or recognized. You can talk for as long as you want and it will piece together what is said, until there is a full 1 second gap in the incoming audio. Here is the SAPI recognition documentation if you want to modify this for your own purposes. Have fun!1 point
-
File Name: AutoIt v3.3.13.6 Beta File Submitter: Jon File Submitted: 18 Jul 2014 File Category: Beta 3.3.13.6 (18th, 2014) (Beta) AutoIt: - Changed: Tables now called Maps. IsTable() now IsMap() - Changed: All Is... functions and UBound() now using internal ByRef optimization. - Changed: Numerous internal rewrites for Dim, Local, Global, Static. Function param passing. Testing needed! - Added: Test versions for MapAppend(), MapExists(), MapKeys() - dot notation versions still available for now. - Fixed: Regression with Dim $var = [1,2] syntax. UDFs: - Fixed: Undeclared variable in File.au3 due to internal changes. Click here to download this file1 point
-
Do, Until...The loop dont repeat....and I dont know why!
czardas reacted to DelioPontes for a topic
It works! Thanks a lot!1 point -
It is already at the bottom of this page which is linked :http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm Jos1 point
-
GUIEvents
jaberwacky reacted to guinness for a topic
How I use WM_MESSAGES efficiently. If someone wants a better example then let me know. Thanks. #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global Enum $GUI_ACTION_LCLIENT, $GUI_ACTION_RCLIENT, $GUI_ACTION_LTITLE ; An enumeration of possible actions. Global $g_iActionCommand = -1 ; Create a single global variable to store a dummy control. Example() Func Example() ; When using WM_MESSAGES users tend to either create a ton of dummy controls and/or global variables that change a state from true to false. ; This example demonstrates that everything can be contained in the main function, so it's then easy to keep control of data being passed around. ; There is no need for tons of global variables and functions. ; It's also a good way of not staying too long in the WM_MESSAGE, which can turn into a huge mess. Local $hGUI = GUICreate('GUIEvents', 500, 500) GUIRegisterMsg($WM_LBUTTONDOWN, 'WM_LBUTTONDOWN') GUIRegisterMsg($WM_NCLBUTTONDOWN, 'WM_NCLBUTTONDOWN') GUIRegisterMsg($WM_RBUTTONDOWN, 'WM_RBUTTONDOWN') $g_iActionCommand = GUICtrlCreateDummy() ; Assign the global dummy control variable with a dummy control id. GUISetState(@SW_SHOW, $hGUI) ; Display the AutoIt GUI. While 1 Switch GUIGetMsg() ; Monitor the gui messages/ids. Case $GUI_EVENT_CLOSE ExitLoop Case $g_iActionCommand ; When a message is sent to the dummy control we have to find out what message was actually sent. $iActionCommand = GUICtrlRead($g_iActionCommand) ; Read the message assigned to the control's "state" parameter e.g. 1001. ; As MakeLong() was used in the event function, find the LoWord of the message that was sent. HiWord could be used for an array index or listview item. $iAction = _WinAPI_LoWord($iActionCommand) Switch $iAction Case $GUI_ACTION_LCLIENT ConsoleWrite('The left button was clicked in the client.' & @CRLF) Case $GUI_ACTION_RCLIENT ConsoleWrite('The right button was clicked in the client.' & @CRLF) Case $GUI_ACTION_LTITLE ConsoleWrite('The left button was clicked in the titlebar.' & @CRLF) EndSwitch EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam GUICtrlSendToDummy($g_iActionCommand, _WinAPI_MakeLong($GUI_ACTION_LCLIENT, 0)) ; $GUI_ACTION_LCLIENT can be swapped for an integer value, but I use an enum value for ease. Return $GUI_RUNDEFMSG EndFunc ;==>WM_LBUTTONDOWN Func WM_NCLBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam GUICtrlSendToDummy($g_iActionCommand, _WinAPI_MakeLong($GUI_ACTION_LTITLE, 0)) ; You don't even need to use MakeLong(). You can just use GUICtrlSendToDummy($g_iActionCommand, $GUI_ACTION_LTITLE), but then the MakeLong() offers the choice to pass ; another integer value such as listview item/subitem in a message such as WM_NOTIFY. Return $GUI_RUNDEFMSG EndFunc ;==>WM_NCLBUTTONDOWN Func WM_RBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam GUICtrlSendToDummy($g_iActionCommand, _WinAPI_MakeLong($GUI_ACTION_RCLIENT, 0)) Return $GUI_RUNDEFMSG EndFunc ;==>WM_RBUTTONDOWN1 point -
Beginner programmer, but long time web designer. (Questions on help)
232showtime reacted to Melba23 for a topic
blackmarket, Triple fail I am afraid: - 1. somdcomputerguy is quite right - please read the Forum rules (the link is also at bottom right of each page) - particularly the bit about not discussing game automation - before you post again. - 2. Please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "This is NOT a general support forum!". I have moved it for you, but would ask you to be more careful in future. - 3. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. So it will not be a surprise that the thread is now locked. But welcome to the AutoIt forum - and see you soon with a legitimate question I hope. M231 point -
Help...about changing tab in mozzila,etc
232showtime reacted to Danp2 for a topic
This is FireFox? If so, there a UDF in the examples forum that should help you.1 point -
I really need to apply >this to SciTE Jump. Why oh why didn't I do this at the beginning. Argh!1 point
-
ImageSearch of several Pictures
232showtime reacted to Melba23 for a topic
moneypulation, Welcome to the AutoIt forums - and I agree with the "cool nick" comments. But the "gamebot" evidence seems clear. Please read the Forum rules (the link is also at bottom right of each page) - particularly the bit about not discussing game automation - before you post again. Thread locked. M231 point -
AutoIt v3.3.13.6 Beta
matwachich reacted to Mat for a topic
You could have ordered maps, but you can't have ordered maps AND efficient lookups, and given that lookups is what maps are for, forget about using maps as stacks. Use an array, it's not hard and it would be faster and more appropriate.1 point