如何使用AutoIT右键单击目录中的文件?

时间:2014-06-09 21:55:40

标签: autoit right-click

我正在尝试模拟在Windows资源管理器中的特定文件或文件夹上自动右键单击鼠标的功能,这是我编写的代码片段,用于模拟:

#include<GUIListView.au3>

Local $filepath = "C:\Windows\addins"

Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
ProcessWait($iPid)

Sleep(1000)

Local $hList = ControlGetHandle("[CLASS:CabinetWClass]", "", "[CLASS:SysListView32; INSTANCE:1]")

Local $aClient = WinGetPos($hList)
Local $aPos = _GUICtrlListView_GetItemPosition($hList, _GUICtrlListView_GetSelectedIndices($hList))

MouseClick("Right", $aClient[0] + $aPos[0] + 4, $aClient[1] + $aPos[1] + 4)

但这会让我回答错误:

  
    

“C:\ Program Files(x86)\ AutoIt3 \ SciTE .. \ autoit3.exe”/ ErrorStdOut“C:\ Users \ asablok \ Desktop \ My Documents \ Calculator.au3”
    “C:\ Users \ asablok \ Desktop \ My Documents \ Calculator.au3”(15):==&gt;     用于非可访问变量的下标:MouseClick(“右”,     $ aClient [0] + $ aPos [0] + 4,$ aClient [1] + $ aPos [1] + 4)     MouseClick(“右”,$ aClient ^错误     退出代码:1时间:1.593

  

有人可以建议我解决如何使用AutoIT解决模拟右键点击的问题。

2 个答案:

答案 0 :(得分:4)

试试这个:

#include<GUIListView.au3>

Local $filepath = "C:\Windows\addins"

Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
ProcessWait($iPid)

Sleep(1000)

Send('+{F10}')

答案 1 :(得分:1)

关于你的第二个问题:

这些是您需要的功能。 摆弄他们,你会明白的。

#include-once
#include <GuiMenu.au3>
;#include <GuiToolbar.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Opt("MustDeclareVars", 1)

Global $gaPopups[1][3] = [[0, 0]]

Func _Lib_PopupGetHwnd($iIndex = 1)
    _Lib_PopupWait()
    Return $gaPopups[$iIndex][0]
EndFunc   ;==>_Lib_PopupGetHwnd

Func _Lib_PopupScan()
    Local $iI, $sClass, $hWnd, $hMenu
    ReDim $gaPopups[1][3]
    $gaPopups[0][0] = 0
    ReDim $winapi_gaWinList[64][2]
    $winapi_gaWinList[0][0] = 0
    $winapi_gaWinList[0][1] = 64
    _WinAPI_EnumWindowsPopup()
    For $iI = 1 To $winapi_gaWinList[0][0]
        $hWnd = $winapi_gaWinList[$iI][0]
        $sClass = $winapi_gaWinList[$iI][1]
        Select
            Case $sClass = "#32768"
                $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
                _Lib_PopupAdd($hMenu, 1, $hWnd)
            Case $sClass = "ToolbarWindow32"
                _Lib_PopupAdd($hWnd, 2, _WinAPI_GetParent($hWnd))
            Case $sClass = "ToolTips_Class32"
                _Lib_PopupAdd($hWnd, 3, _WinAPI_GetParent($hWnd))
        EndSelect
    Next
EndFunc   ;==>_Lib_PopupScan

Func _Lib_PopupWait()
    Local $iLoop = 0
    While $iLoop < 50
        If $gaPopups[0][0] > 0 Then Return
        Sleep(100)
        _Lib_PopupScan()
        $iLoop += 1
    WEnd
    ConsoleWrite("Timeout waiting for popup window to appear" & @CRLF)
EndFunc   ;==>_Lib_PopupWait

Func _Lib_PopupAdd($hWnd, $iType, $hParent)
    Local $iCount
    $gaPopups[0][0] += 1
    $iCount = $gaPopups[0][0]
    ReDim $gaPopups[$iCount + 1][3]
    $gaPopups[$iCount][0] = $hWnd
    $gaPopups[$iCount][1] = $iType
    $gaPopups[$iCount][2] = $hParent
EndFunc   ;==>_Lib_PopupAdd