Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/07/2013 in all areas

  1. It is hard for me to contribute to any meaningful part of this code as I am still trying to understand it all (though I love it and have used it for some things already). I think the original simple Spy was awesome. My tiny contribution is shrinking it down and adding some functionality with some additional hotkeys to copy to the clipboard, open and paste into Notepad, and toggle the mouse capture on and off. I find it easier to spy things this way. Hope it is helpful to someone. #include <GuiEdit.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #include <Misc.au3> #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os dim $oldUIElement ; To keep track of latest referenced element ;~ Some references for reading ;~ [url=http://support.microsoft.com/kb/138518/nl]http://support.microsoft.com/kb/138518/nl[/url] tagpoint structures attention point ;~ [url=http://www.autoitscript.com/forum/topic/128406-interface-autoitobject-iuiautomation/]http://www.autoitscript.com/forum/topic/128406-interface-autoitobject-iuiautomation/[/url] ;~ [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ff625914(v=vs.85).aspx]http://msdn.microsoft.com/en-us/library/windows/desktop/ff625914(v=vs.85).aspx[/url] HotKeySet("{ESC}", "Close") ; Set ESC as a hotkey to exit the script. HotKeySet("^w", "GetElementInfo") ; Set Hotkey Ctrl+M to get some basic information in the GUI HotKeySet("^c", "_copyedit") HotKeySet("^p", "_pasteedit") HotKeySet("^t", "_togglemouse") #Region ### START Koda GUI section ### Form=c:\users\rc01712\desktop\uiautomation\spy2.kxf $Form1_1 = GUICreate("Spy 2", 630, 479, 192, 132) $Edit1 = GUICtrlCreateEdit("", 8, 16, 385, 441) GUICtrlSetData(-1, "Edit1") $Label1 = GUICtrlCreateLabel("Control+w to capture information", 400, 48, 201, 20) $Label2 = GUICtrlCreateLabel("Control+p to open Notepad and paste", 400, 100, 221, 20) $Label3 = GUICtrlCreateLabel("Control+c to copy Info to Clipboard", 400, 74, 211, 20) $Label4 = GUICtrlCreateLabel("Esc to exit", 400, 146, 64, 20) $Label5 = GUICtrlCreateLabel("Control+t to toggle mouse capture", 400, 125, 209, 20) $Clear = GUICtrlCreateButton("Clear edit", 448, 192, 121, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _UIA_Init() dim $content="" dim $toggle=0 ; Run the GUI until the dialog is closed While true $msg = GUIGetMsg() sleep(100) if _ispressed(01) AND $toggle=1 Then getelementinfo() endif if $msg=$clear Then GUICtrlSetData($Edit1,"") EndIf If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd func _copyEdit() $content=guictrlread($Edit1) ClipPut($content) EndFunc func _pasteedit() run("notepad.exe") _UIA_setVar("Notepad.mainwindow","classname:=Notepad") ; works _UIA_setVar("Notepad.document","classname:=Edit") _UIA_action("Notepad.Mainwindow","setfocus"); works send("^v") EndFunc func _togglemouse() if $toggle=0 then $toggle=1 Else $toggle=0 EndIf ;MsgBox("","",$toggle) EndFunc Func GetElementInfo() Local $hWnd Local $tStruct = DllStructCreate($tagPOINT) ; Create a structure that defines the point to be checked. ;~ Local $tStruct = DllStructCreate("INT64,INT64") ;~ Local $tStruct =_AutoItObject_DllStructCreate($tagPoint) ToolTip("") $x=MouseGetPos(0) $y=MouseGetPos(1) DllStructSetData($tStruct, "x", $x) DllStructSetData($tStruct, "y", $y) consolewrite(DllStructGetData($tStruct,"x") & DllStructGetData($tStruct,"y")) ;~ consolewrite("Mouse position is retrieved " & @crlf) $objUIAutomation.ElementFromPoint($tStruct,$pUIElement) ;~ $objUIAutomation.ElementFromPoint(DllStructGetPtr($tStruct),$pUIElement) ;~ consolewrite("Element from point is passed, trying to convert to object ") $oUIElement = objcreateinterface($pUIElement,$sIID_IUIAutomationElement, $dtagIUIAutomationElement) if isobj($oldUIElement) Then if $oldUIElement=$oUIElement then return endif endif _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN) ; Clears Red outline graphics. GUICtrlSetData($Edit1, "Mouse position is retrieved " & $x & "-" & $y & @CRLF) $oldElement=$oUIElement If IsObj($oUIElement) Then ;~ ConsoleWrite("At least we have an element " & "[" & _UIA_getPropertyValue($oUIElement, $UIA_NamePropertyId) & "][" & _UIA_getPropertyValue($oUIElement, $UIA_ClassNamePropertyId) & "]" & @CRLF) GUICtrlSetData($Edit1, "At least we have an element " & "[" & _UIA_getPropertyValue($oUIElement, $UIA_NamePropertyId) & "][" & _UIA_getPropertyValue($oUIElement, $UIA_ClassNamePropertyId) & "]" & @CRLF,1) $text1="Title is: <" & _UIA_getPropertyValue($oUIElement,$UIA_NamePropertyId) & ">" & @TAB _ & "Class := <" & _UIA_getPropertyValue($oUIElement,$uia_classnamepropertyid) & ">" & @TAB _ & "controltype:= " _ & "<" & _UIA_getControlName(_UIA_getPropertyValue($oUIElement,$UIA_ControlTypePropertyId)) & ">" & @TAB _ & ",<" & _UIA_getPropertyValue($oUIElement,$UIA_ControlTypePropertyId) & ">" & @TAB _ & ", (" & hex(_UIA_getPropertyValue($oUIElement,$UIA_ControlTypePropertyId)) & ")" & @TAB & @CRLF $text1= $text1 & @CRLF & getAllPropertyValues($oUIElement) ConsoleWrite($text1) GUICtrlSetData($Edit1, "Having the following values for all properties: " & @crlf & $text1 & @CRLF, 1) _GUICtrlEdit_LineScroll($Edit1, 0, 0 - _GUICtrlEdit_GetLineCount($Edit1)) $t=stringsplit(_UIA_getPropertyValue($oUIElement, $UIA_BoundingRectanglePropertyId),";") _DrawRect($t[1],$t[3]+$t[1],$t[2],$t[4]+$t[2]) EndIf EndFunc ;==>Example Func Close() Exit EndFunc ;==>Close
    1 point
  2. Wombat, Oops, forgot that bit! How about this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> If Not WinExists("Untitled - Notepad") Then Run("Notepad.exe") $hNotepad = WinWaitActive("Untitled - Notepad") Else $hNotepad = WinGetHandle("Untitled - Notepad") EndIf WinMove($hNotepad, "", 100, 100, 500, 500) Opt("GUIOnEventMode", 1) Opt("GUICloseOnEsc", 1) Global $fChild = False HotKeySet("q", "_SH_Child") Global $hGUI_Child _Create_Child() While 1 Sleep(10) If Not WinExists($hNotepad) Then Exit EndIf _Position_Child($hNotepad) WEnd Func _Create_Child() $hGUI_Child = GUICreate("Follower", 200, 500, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $hNotepad) GUISetBkColor(0xCCFFCC) _Position_Child($hNotepad) EndFunc ;==>_Create_Child Func _SH_Child() $fChild = Not $fChild If $fChild Then If Not $hGUI_Child Then _Create_Child() EndIf DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI_Child, "int", 1000, "long", 0x00040001) ; $AW_SLIDE_IN_LEFT WinActivate($hNotepad) Else DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI_Child, "int", 1000, "long", 0x00050002) ; $AW_SLIDE_OUT_LEFT EndIf EndFunc ;==>_SH_Child Func _Position_Child($hNotepad) Local $aGUI_Main_Pos = WinGetPos($hNotepad) WinMove($hGUI_Child, "", $aGUI_Main_Pos[0] + $aGUI_Main_Pos[2] + 2, $aGUI_Main_Pos[1]) EndFunc ;==>_Position_Child M23
    1 point
  3. Wombat, A "proof of concept" script that uses "q" as a HotKey for child activation: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> If Not WinExists("Untitled - Notepad") Then Run("Notepad.exe") $hNotepad = WinWaitActive("Untitled - Notepad") Else $hNotepad = WinGetHandle("Untitled - Notepad") EndIf WinMove($hNotepad, "", 100, 100, 500, 500) Opt("GUIOnEventMode", 1) Opt("GUICloseOnEsc", 1) Global $fChild = False HotKeySet("q", "_SH_Child") Global $hGUI_Child _Create_Child() GUIRegisterMsg($WM_MOVE, "_Position_Child") While 1 Sleep(10) If Not WinExists($hNotepad) Then Exit EndIf WEnd Func _Create_Child() $hGUI_Child = GUICreate("Follower", 200, 500, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $hNotepad) GUISetBkColor(0xCCFFCC) _Position_Child($hNotepad, 0, 0, 0) EndFunc ;==>_Create_Child Func _SH_Child() $fChild = Not $fChild If $fChild Then If Not $hGUI_Child Then _Create_Child() EndIf DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI_Child, "int", 1000, "long", 0x00040001) ; $AW_SLIDE_IN_LEFT WinActivate($hNotepad) Else DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI_Child, "int", 1000, "long", 0x00050002) ; $AW_SLIDE_OUT_LEFT EndIf EndFunc ;==>_SH_Child Func _Position_Child($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam If $hWnd <> $hNotepad Then Return Local $aGUI_Main_Pos = WinGetPos($hNotepad) WinMove($hGUI_Child, "", $aGUI_Main_Pos[0] + $aGUI_Main_Pos[2] + 2, $aGUI_Main_Pos[1]) EndFunc ;==>_Position_Child Let me know if you are interested and we can work on getting it as you want. M23
    1 point
  4. continyu, This is as close to what you want as I could get. #include <StaticConstants.au3> #include <DateTimeConstants.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #AutoIt3Wrapper_Add_Constants=n local $gui010 = guicreate('Date Time Example',300,300) local $DTctl = GUICtrlCreateDate('',20,20,200,20) local $status = guictrlcreatelabel('',20,280,260,20,$SS_SUNKEN) GUICtrlSetColor(-1,0xaa0000) guisetstate() GUIRegisterMsg($WM_NOTIFY,'WM_NOTIFY') while 1 switch guigetmsg() case $GUI_EVENT_CLOSE Exit case $DTctl ConsoleWrite('date selected = ' & guictrlread($DTctl) & @LF) EndSwitch wend func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMDATETIMECHANGE $tNMDATETIMECHANGE = dllstructcreate($tagNMDATETIMECHANGE, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMDATETIMECHANGE, "hWndFrom")) $iIDFrom = DllStructGetData($tNMDATETIMECHANGE, "IDFrom") $iCode = DllStructGetData($tNMDATETIMECHANGE, "Code") local $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW switch $hWndFrom case guictrlgethandle($DTctl) switch $iCode case $DTN_DATETIMECHANGE if dllstructgetdata($tNMDATETIMECHANGE, 'DOW') = 0 then guictrlsetdata($status,' Invalid Selection - Re-pick Date') GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, ' SUNDAY_INVALID - REPICK') endif case $DTN_DROPDOWN guictrlsetdata($status,'') guictrlsendmsg($DTctl, $DTM_SETFORMAT_, 0, "dddd, MMMM dd, yyyy") EndSwitch EndSwitch return $GUI_RUNDEFMSG endfunc kylomas
    1 point
  5. AndyCollette, Here is my take on how you might do it. The ####### lines show the areas I changed from the OP's first script: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <SliderConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiButton.au3> #include <GuiListView.au3> #include <Constants.au3> #include <Misc.au3> #include <GuiToolTip.au3> #include <Array.au3> #include <File.au3> Global $ITEMID, $Lista1 Global $CABECERA = "Archivo |Ruta " $Ancho = 333 $Alto = 300 #region ### START Koda GUI section ### $Form1 = GUICreate("Aplicacion", $Ancho, $Alto, 318, 184, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) ;;;; LISTA $Lista1 = GUICtrlCreateListView($CABECERA, 0, 0, $Ancho, 257) GUICtrlSetState($Lista1, $GUI_DROPACCEPTED) _GUICtrlListView_SetExtendedListViewStyle($Lista1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_INFOTIP)) ;;;; BOTONES $BTNAGREGAR = GUICtrlCreateButton("Add file", 15, 265, 90, 25) GUICtrlSetTip(-1, 'Añadir archivos ') $BTNEMPEZAR = GUICtrlCreateButton("Run", 123, 265, 90, 25) GUICtrlSetTip(-1, 'Ejecutar') $BTNBORARSELECT = GUICtrlCreateButton("Delete", 230, 265, 90, 25) GUICtrlSetTip(-1, 'Borrar') GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### ; ############################################################################### Global $sFolder = FileSelectFolder("Select a folder", "") $aList = _FileListToArray($sFolder, "*.*", 1) For $i = 1 To $aList[0] $ITEMID = _GUICtrlListView_AddItem($Lista1, StringTrimRight($aList[$i], 4)) _GUICtrlListView_AddSubItem($Lista1, $ITEMID, $sFolder & '\' & $aList[$i], 1) Next ; ############################################################################### While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $BTNAGREGAR _Agregararchivo() Case $BTNEMPEZAR _SelectArchivo() Case $BTNBORARSELECT _BorrarSeleccionado() EndSwitch WEnd Func _Agregararchivo() $Carpeta = FileOpenDialog('Add file', '', ' All(*.*) ', 5, '', $Form1) $Filediv = StringSplit($Carpeta, '|') If $Filediv[0] <> 1 Then ; For $N = 2 To $Filediv[0] $ITEMID = _GUICtrlListView_AddItem($Lista1, StringTrimRight($Filediv[$N], 4)) _GUICtrlListView_AddSubItem($Lista1, $ITEMID, $Filediv[1] & '\' & $Filediv[$N], 1) Next Else $Filediv = StringSplit($Carpeta, '\') ;Añadir un archivo $ITEMID = _GUICtrlListView_AddItem($Lista1, StringTrimRight($Filediv[$Filediv[0]], 4)) _GUICtrlListView_AddSubItem($Lista1, $ITEMID, $Carpeta, 1) EndIf EndFunc ;==>_Agregararchivo Func _SelectArchivo() If _GUICtrlListView_GetItemCount($Lista1) <> 0 Then $A = 0 Do $A = $A + 1 If _GUICtrlListView_GetItemSelected($Lista1, $A) = True Then $Archivo = $A _Aplicar(_GUICtrlListView_GetItemText($Lista1, $A, 1)) $A = _GUICtrlListView_GetItemCount($Lista1) $Selection = 0 Else $Selection = 1 EndIf Until $A = _GUICtrlListView_GetItemCount($Lista1) If $Selection = 1 Then $Archivo = 0 _Aplicar(_GUICtrlListView_GetItemText($Lista1, 0, 1)) _GUICtrlListView_SetItemSelected($Lista1, 0) EndIf EndIf EndFunc ;==>_SelectArchivo Func _Aplicar($RUTAF) $Aplicar = ShellExecute($RUTAF) EndFunc ;==>_Aplicar ; ############################################################################### Func _BorrarSeleccionado() $var = MsgBox("1", "Atencion", "Estas seguro que quieres Borarlo?") If $var = 1 Then $ELIMINADO = _GUICtrlListView_GetSelectedIndices($Lista1, True) ; Get an array of teh selected indices For $i = 1 To $ELIMINADO[0] $sText = _GUICtrlListView_GetItemText($Lista1, $ELIMINADO[$i], 1) FileDelete($sText) _GUICtrlListView_DeleteItem(GUICtrlGetHandle($Lista1), $ELIMINADO[$i]) Next Else EndIf EndFunc ;==>_BorrarSeleccionado ; ###############################################################################Please ask if you have any questions. M23
    1 point
×
×
  • Create New...