davidacrozier

Mouse click on explorer window...item to click is not displayed on screen

12 posts in this topic

#1 ·  Posted (edited)

I am attempting to drag and drop a file from one windows explorer window to another windows explorer window (henceforth referred to as window1 and window2).  I am not using the web.  I have used autowinexp.au3 (taken from LarsJ's automatewindowsexplorer.au3) to give focus (function GetFileFocus)  to a file on window1.   The problem is that sometimes the file with the focus is not displayed on window1 because it is farther down the list than what is displayed in window1.  There are other ways to accomplish this (like copy and paste) but I want to emulate the GUI doing a drag and drop.  I work as a digital forensicator and my task is to examine what artifacts are left behind on move/copy vs a drag and drop.  Please note that when I open window1 and window2 they are on top of each other, so I drag window2 over about 1150 pixels and that part works great.    

My code is listed below.  Please understand that I have tried several different methods to accomplish this task.  The last one was to estimate that the top of the window1 header is approximately 320 pixels and to multiply the index of the file by 20 pixels since that appears to be the approximate height of individual files using the AutoIT Windows Info tool.  Ideally the program would search window1 for the file name text and provide a mouse position for it.  Or the program would allow me to scroll to where the file name is located.  Any and all ideas are welcome.

Using Windows 10

AutoIT v3.3.14.2

Thanks!

DavidaCrozier

PS Any problems in autowinexp.au3 are mine and not the author of automatewindowsexplorer.au3.  

 

DragAndDropForum.au3

autowinexp.au3

Edited by davidacrozier

Share this post


Link to post
Share on other sites



#2 ·  Posted

Hello. Try to add all the references. I did this PoC without using extern UDF.  Tested in Windows 10 (Spanish Lang)

 

#RequireAdmin ; Runs script as admin user
#include <AutoItConstants.au3>


Local $sTextDesktop="Escritorio"  ;Use "Desktop" for English OS
Local $sTextDocuments="Documentos" ;Use  "Documents" for English OS

;just for closing the windows if they exist
WinClose("[CLASS:CabinetWClass]", $sTextDesktop)
WinClose("[CLASS:CabinetWClass]",$sTextDocuments)

Local $sFile = @UserProfileDir & "\Desktop\testautoit.txt"
FileWrite($sFile,"My Demo File")
Local $filePath1 = @UserProfileDir & "\Desktop"
Local $filePath2 = @UserProfileDir & "\Documents"

Local $iPid1 = Run("explorer.exe " & $filePath1)
Local $hHandle1 = WinWait("[CLASS:CabinetWClass]", $sTextDesktop)


Local $iPid2 = Run("explorer.exe " & $filePath2)
Local $hHandle2 = WinWait("[CLASS:CabinetWClass]", $sTextDocuments)

ConsoleWrite("Handle1: " & $hHandle1 & @TAB & "Title: " & WinGetTitle($hHandle1) & @CRLF)
ConsoleWrite("Handle2: " & $hHandle2 & @TAB & "Title: " & WinGetTitle($hHandle2) & @CRLF)


Local $iWidth = @DesktopWidth / 2
Local $iHeight = @DesktopHeight - 50
ConsoleWrite($iWidth & @CRLF)
ConsoleWrite($iHeight & @CRLF)

WinMove($hHandle1, "", 1, 1, $iWidth, $iHeight) ;move window 1
WinMove($hHandle2, "", $iWidth, 1, $iWidth, $iHeight) ;move window 2
Sleep(500)
WinActivate($hHandle1, "")


Local $oShell = ObjCreate("Shell.Application")
Local $oDocument = 0
For $oWindow In $oShell.Windows
    If $hHandle1 = $oWindow.HWND Then
        ConsoleWrite(Hex($oWindow.HWND) & @CRLF)
        $oDocument = $oWindow.Document
    EndIf
Next


If IsObj($oDocument) Then
    Local $bFound = False
    Local $iCountIndex = 0
    Local $oItems = $oDocument.Folder.Items

    For $oItem In $oItems
        If $iCountIndex = 0 Then $oDocument.SelectItem($oItem, 1) ;select First Item
        If $oItem.Path = $sFile Then
            ConsoleWrite($oItem.Path & @CRLF)
            $bFound = True
            ExitLoop
        EndIf
        $iCountIndex += 1
    Next
    If $bFound Then
        ConsoleWrite($iCountIndex & @CRLF)
        ControlSend($hHandle1, "", "", "{DOWN " & $iCountIndex & "}")
        Local $aPixel = PixelSearch(0, 0, $iWidth, $iHeight, 0xCCE8FF)
        If IsArray($aPixel) Then
;~          MouseMove($aPixel[0] + 10, $aPixel[1] + 10)
;~          MouseMove($iWidth + ($iWidth / 2), 10)
            MouseClickDrag($MOUSE_CLICK_LEFT, $aPixel[0] + 10, $aPixel[1] + 10, $iWidth + ($iWidth / 2), 10)
        EndIf
        Else
        MsgBox(0,"Information","File Not Found")
        EndIf

EndIf

Exit

Saludos

 

1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted

@Danyfirex  This works amazingly well.  Very simple but elegant.  I never knew that you could drag to the top of the window.  Muchas gracias. Realmente aprecio su ayuda.

Share this post


Link to post
Share on other sites

#5 ·  Posted

@LarsJ Thanks so much for your solution.  A couple of questions.  You do not seem to worry about using the ObjCreateInterface even though it is marked as experimental.  Is this your code doing the function?  Second, where did you learn to code with the interfaces and objects within Windows?  I would love to have a better command of these coding techniques.  If I am understanding your code correctly... the Realize method for the VirtualItem makes it visible.  Does this include focus for the item?   Can I then get the mouse position for this item or do I need to search the array for the name?  Hope this makes sense to you.

Thanks again. 

Share this post


Link to post
Share on other sites

#6 ·  Posted

You're welcome. (De nada ;))

 

About question to LarsJ. I know He can answer better than me But I want to write a bit.

ObjCreateInterface It's not experimental. We have been using it since years without any bug. 

To learn about  interfaces and objects  You need to know about COM/Interface Implementation, check msdn doc.

Then You can search over the forum We have a lot of examples using ObjCreateInterface. 

 

About Focus and Position. Sure It's possible. I can't check right now but sure LarsJ will provide a solution. Of course you can try by yourself probably reading the whole LarsJ 's topic about Automation Windows Explorer You'll find the answer or a correct way to go to.

 

Saludos

 

 

 

1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted

@Danyfirex would you please explain to me what the following statement does.

Local $aPixel = PixelSearch(0, 0, $iWidth, $iHeight, 0xCCE8FF)

I know that PixelSearch searches a rectangle of pixels for the pixel color provided.  What color did you choose and why?  Then the statement returns an array containing the x,y coordinates of the results of the search.  I am just trying to understand why you are searching for that 0xCCE8FF color and how  you knew to do the search,

Thanks again!

Share this post


Link to post
Share on other sites

#8 ·  Posted

Look:

https://prnt.sc/fwus0y

 

If the Selection color is Diferent It will fail.

 

Saludos

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

Excellent. I just wanted to understand what was going on.

Share this post


Link to post
Share on other sites

#10 ·  Posted

Hello again.  I am using my modified version of automatewindowsexplorer.au3 to get the focus for folders.  This script creates a folder on desktop, documents, and temp folders.  Then it turns around and deletes those same folders.  It appears that the folder to be deleted has focus but something in my code is causing it to deselect the focus before I can delete the file.  As always your help is appreciated.  This script uses the GUI in order to observe what artifacts are created by windows.

 

Davida Crozier

 

deleteFileTest.au3

autowinexp.au3

Share this post


Link to post
Share on other sites

#11 ·  Posted

Are you using the Windows Explorer window to delete the folder? Why?

Use DirRemove instead and just pass it your folder path, not sure I've ever seen anyone try to do it the way you're doing it.

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#12 ·  Posted

@BrewManNH...I am using this script to test some digital forensics artifacts that are left behind when the Windows GUI does these functions.  I need to ensure that the Windows GUI is performing the delete.  Thanks for your reply.

One additional note as I keep working with this issue.  I am attempting to get the delete to work on folders when I include the appropriate automatewindowsexplorer.au3 code inline with my script.  I just wasn't sure why the folder lost the focus.

Any help is greatly appreciated.

DavidaCrozier

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • PeteF
      By PeteF
      Full script w/details in comments below, just in case you need to run it to see the problem.  Basically WinGetPos is incorrectly returning the W & H sizes, while at the same time correctly returning the positions. To compound the problem, I ran the same script on 2 different PCs and it gets2 different results as follows:
      Win7 Pro PC.. GUICreate used to set W:300, H:100.       WinGetPos returns W:307, H:127  (PC screen res: 1366x768)
      WinXP PC..... GUICreate used to set W:300, H:100.       WinGetPos returns W:308, H:134   (PC screen res: 1152x864)
      The bigger problem occurs when you consider I want to save the Window sizes and recreate the window at a later date. but due to this problem, each time I ran the program the Window would get larger and larger.    --pete
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; SCRIPT DESC.: Simple script here. Create & display one Window of a specific ; size & position. This Window is always ON TOP of other windows. ; User may resize the window to cover up unwanted content (as in use with a Web-Browser). ; Upon user closing the Window, DEBUG msgbox in script returns window size & position ; to be used in further development of this script. ; ; PROBLEM: If user does not resize the Window and simply clicks "X" to close the window, ; the DEBUG msgbox is reporting the wrong SIZES. It's actually the AutoIt WinGetPos ; function that is returning correct positions, but incorrectly returning the sizes. ; It should be returning 300 (W), 100 (H), but it's incorrectly returning 307 (W), 127 (H) ; _MAIN() Func _MAIN() ;Local $sFilePath = "..\GUI\logo4___.gif" Local $l_SizeWidth_1, $l_SizeHeight_1, $l_PosLeft_1, $l_PosTop_1 ; Defaults for Window 1 Size and Position $l_SizeWidth_1 = 300 $l_SizeHeight_1 = 100 $l_PosLeft_1 = 50 $l_PosTop_1 = 50 ; Create re-sizable GUI window/form that is blank with a black background and stays on TOP over over windows. Local $hGUI = GUICreate("COVER UNWANTED CONTENT", $l_SizeWidth_1, $l_SizeHeight_1, $l_PosLeft_1, $l_PosTop_1, _ $WS_OVERLAPPEDWINDOW, $WS_EX_TOPMOST) ; Black Background GUISetBkColor(0x000000) ;GUICtrlCreatePic("..\GUI\msoobe.jpg", 0, 0, 400, 100) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Create a picture control with a transparent image. ;GUICtrlCreatePic($sFilePath, 0, 0, 169, 68) ; Display the Window GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() ; CASE IF USER X's out, CLOSE THE WINDOWS & QUIT Case $GUI_EVENT_CLOSE ExitLoop ; CASE Open a second window EndSwitch WEnd ; Obtain the window(s) Size & Positions _WindowPositionAndSize($hGUI) ; Save the window(s) size & positions ; TBD ; Delete the previous GUIs and all controls. GUIDelete($hGUI) EndFunc ;==>_MAIN Func _WindowPositionAndSize($WindowID) ; Retrieve the position as well as height and width of the window. Local $aPos = WinGetPos($WindowID) ; DEBUG msgbox ; Display the array values returned by WinGetPos. MsgBox(0, "", "X-Pos: " & $aPos[0] & @CRLF & _ "Y-Pos: " & $aPos[1] & @CRLF & _ "Width: " & $aPos[2] & @CRLF & _ "Height: " & $aPos[3] ) ; DEBUG notes ; Width 300 off by a factor of.. 0.9740261 ; Height 100 off by a factor of.. 0.7874017 ; I was hoping to add in some correction factors, but thse factors ; change dramatically at different Width & Height settings. Need a better fix! EndFunc ;==>_WindowPositioAndSize  
       
    • autog
      By autog
      I left a comment in another thread on multitouch, but my question can be missed there and the solution might have no relationship with simulating multi-touch.
      So, is there any possibility to get the multiple x,y coordinates on a multi-touch device?
      Smth like mousegetpos, but multiple (?)
      Thank you for any idea / direction towards a solution.
    • Reizvoller
      By Reizvoller
      Func workSpaceSetup () ConsoleWrite ("workSpaceSetup" &@CRLF) $workSpace = WinGetHandle ("some site - Google Chrome") ConsoleWrite ($workSpace&@CRLF) $pos1 = WinGetPos ($workSpace) WinMove ($workSpace , "", $pos1[0] , $pos1[1] , 1366, 768, 0) EndFunc So the script is first, the error I get is second in the quote.
      This is one function of many for an app I am building but it is the first one that runs so I know there aren't other things at play here.
      The idea is to keep the window in the same space it is when the script runs but just resize it as this app is used across multiple computers with different screen resolutions.
      Could someone please elaborate upon what "Subscript used on non-accessible variable" means? 
      Oh and the variable is declared as "Global $pos1 = 0" at the top outside of any functions with the other global variables.
      Any advice would be greatly appreciated!
      -Reiz
    • DiveHigh
      By DiveHigh
      Hello There!  
      I've encountered a small issue i just cant seem to program my way out of...

      What im doing is:        ;or rather, what im trying to do is
      Pixelsearch for a color, within a part of my screen,
      If color is present, i will rightclick it, for a menu to appear,
      in which i want to Leftclick an option. Simplicity itself.   

      The issue is that because this menu appears in different parts of my screen, its complicated to select the option i want to click.
      There is no special color to it, and i cannot define the area in which to click, because the menu appears different places.
      The only thing that is in common for the menu is that the Leftclick needs to be (lets say) 30pixels below the rightclick
      .

      What can be done,  but seemingly not by me, is to get the coordinates of the rightclick, and use them as the "starting point" from where the coordinates for the leftclick will be.
      (Not sure if that makes sence, but maybe the code below will help you understand)

      You guys like example codes, so therefore i will give it my best shot, and hope it proves usefull

      $pos = Pixelsearch(200, 400, 200, 400, 0xFFFFFF)        ;This color is what i need to rightclick to bring up the menu
      If not @Error then                                                               ;If the color is present
      (Mouseclick("Right", $pos[0], $pos[1], 1, 1)                   ;Rightclick it, to bring up menu
      ;Here comes the part i cannot get to work
      $x = MousegetPos(X)                                                          ;To get the Coordinate "X", so we can calculated with it for the position of the leftclick
      $y = MousegetPos(Y)                                                           ; To get the Coordinate "Y", so that can be calculated with for the position of the leftclick

      MouseClick("Left", $x[0], $y-30[1], 1, 1)                         ;This was supposed to give me a leftclick that is 30pixels below the rightclick.
      (The MouseGetPos(X), may seem as a waste of space in this example, but in my script i will need both. 
              Im only using one in the example, mainly so that i wont confuse myself, but also to make it easier to digest for you guys)


      I have not been able to find any topic that covers this, but my apologies if such a topic already exist in the forums. 

      Maybe while im at it, can i ask,   what good does the [0] and [1] do, when using a "$variable" as coordinate?   


      Thanks in advance
      - DiveHigh
    • nitekram
      By nitekram
      I am trying to do something, but it appears that I am having issues with trying to get the right functions called, in the right order.
      What I want to do is move a window to a certain position and then move it back, but as stated, the order appears to be an issue, as if the window is minimized, the wingetclientsize is not able to pull the info, not is the wingetpos. It appears to be able to get the size and position of the window in question is activated, but I have to activate it first, but that defeats the purpose, as once activated, the functions called to get the position and size, are not correct, as the screen is now active. I have tried to use wingetstate, to get the state first, but I am not sure how to move the window back to the original location with the right state.
      If window is minimized, I want it to go back to minimized state, as well as keeping the window size the same, so if the user activates the window, the user does not have to resize it.
      If the window is active and is on another screen, it appears I do not have the same issue.
      Here is my attempt, but I have tried other combinations. Has anyone got an idea on how to resolve this issue?
      Func MoveVNC($Move) CreateLogEntry("Called MoveVNC($Move) $Move = " & $Move) Local $aStartBar = StartBar() Local $bMove = False Local $VNC = 'NAMEOFWINDOW' Static $aWin_VNC_Pos = '' Static $iWin_VNC_State = '' Static $aWin_VNC_Size = '' #cs ;$aWin_VNC_Pos = WinGetPos($VNC, '') MsgBox('','VNC POS','') _ArrayDisplay(WinGetPos($VNC, '')) MsgBox('','VNC STATE',WinGetState($VNC, '')) WinActivate($VNC) Sleep(20) WinWaitActive($VNC, '', 10) Sleep(20) Local $aSize = WinGetClientSize($VNC, '') MsgBox('','VNC SIZE','') _ArrayDisplay($aSize) #ce If $Move = 'Get' Then Opt("WinTitleMatchMode", -1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase If WinExists($VNC) Then WinActivate($VNC) Sleep(20) WinWaitActive($VNC, '', 10) Sleep(20) $aWin_VNC_Pos = WinGetPos($VNC, '') Sleep(20) ;_ArrayDisplay($aWin_VNC_Pos, '$aWin_VNC_Pos') $iWin_VNC_State = WinGetState($VNC, '') Sleep(20) $aWin_VNC_Size = WinGetClientSize($VNC, '') ;_ArrayDisplay($aWin_VNC_Size) ;MsgBox('','$VNC',$VNC) ;MsgBox('', '$iWin_VNC_State', $iWin_VNC_State) ;WinSetState($VNC, '', @SW_MAXIMIZE) ;Sleep(20) WinMove($VNC, '', 0, 0, 1600, 950) ; - (3 * $aStartBar[3]) Sleep(20) ;MouseClick('Left', 1764, 174) $bMove = True Else MsgBox($MB_TOPMOST, 'ERROR GET', 'Window ' & $VNC & ' Does not exists - VNC is not running!') EndIf If Not $bMove Then CreateLogEntry("MoveVNC(GET) FAILED") Return False Else CreateLogEntry("MoveVNC(GET) PASSED") Return True EndIf ElseIf $Move = 'Put' Then CreateLogEntry("Called MoveVNC($Move) $Move = " & $Move) If WinExists($VNC) Then ;WinSetState($VNC, '', @SW_RESTORE) ;If @error Then MsgBox('', '', @error) ;Sleep(20) WinMove($VNC, '', $aWin_VNC_Pos[0], $aWin_VNC_Pos[1], $aWin_VNC_Pos[2], $aWin_VNC_Pos[3]) If @error Then MsgBox('', '', @error) Sleep(20) ;WinSetState($VNC, '', $iWin_VNC_State) ;If @error Then MsgBox('', 'Not setting state', @error & ' ' & $VNC) ;Sleep(20) $bMove = True Else MsgBox($MB_TOPMOST, 'ERROR PUT', 'Window ' & $VNC & ' Does not exists - VNC is not running!') EndIf If Not $bMove Then CreateLogEntry("MoveVNC(PUT) FAILED") Return False Else CreateLogEntry("MoveVNC(PUT) PASSED") Return True EndIf EndIf CreateLogEntry(" Returned from MoveVNC()") EndFunc ;==>MoveVNC