【问题标题】:How to right click on a file present in a directory using AutoIT?如何使用 AutoIT 右键单击​​目录中存在的文件?
【发布时间】:2014-07-30 13:12:29
【问题描述】:

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

#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) : ==> 不可访问变量上使用的下标。:MouseClick("Right", $aClient[0] + $aPos[0] + 4, $aClient[1] + $aPos[1] + 4) MouseClick("右", $aClient^ 错误 退出代码:1 时间:1.593

谁能给我建议一个解决方法来解决这个使用 AutoIT 模拟右键单击的问题。

【问题讨论】:

    标签: autoit right-click


    【解决方案1】:

    试试这个:

    #include<GUIListView.au3>
    
    Local $filepath = "C:\Windows\addins"
    
    Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
    ProcessWait($iPid)
    
    Sleep(1000)
    
    Send('+{F10}')
    

    【讨论】:

    • 它似乎工作!非常感谢:DI能够实现我想要的,现在我还有一个与此相关的问题,我如何从右键单击后出现的菜单中选择特定选项,您对此有什么想法吗?跨度>
    • BlockInput(1) Send("{down 8}") Send("{ENTER}") BlockInput(0) 我建议您在使用 Send 时避免干扰脚本时使用 BlockInput ()
    • 嗨 Milos 感谢您的回复,让我解释一下我的情况,我想做的是,首先我应该能够打开所需的目录让我们说“C:/”并在那个目录中我需要右键单击特定文件夹并从出现的菜单中获取选项列表,例如如果菜单具有 Open、OpenWith 和 Properties 我需要将所有这些选项放在一个数组中。
    【解决方案2】:

    第二个问题:

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

    #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
    

    【讨论】:

    • 是的,我找到了这个例子,但我无法修改它以仅选择所需的选项:(
    • 我想获取上下文菜单的内容,上面的代码使用了一个常量文件,它可能会根据我使用的 Windows 版本而有所不同,有没有办法获取上下文菜单窗口并使用 AutoIt 获取数组或列表中的菜单项列表,我在 AutoIT 论坛上进行了研究,但那里提供的帮助很少:( 遗憾的是
    • 这就是我所需要的,问题是我正在尝试自动化插件,我首先打开所需的文件夹,然后右键单击特定文件,然后从列表中弹出菜单中可用的菜单 我需要选择一个我需要单击的菜单,因此我需要弹出菜单中所有可用菜单项的列表,然后单击左键执行该过程,是不知何故,它可以使用 AutoIT 来完成。我搜索了很多但不幸:(
    • "显示弹出窗口后,使用_Lib_PopupGetHwnd获取弹出菜单的句柄。然后您可以将此句柄传递给A3LMenu.au3中的任何函数(如阅读文本,打开子菜单等)。如果您查看 _Menu_ClickPopUp 的代码,您会看到它的作用。"
    • 我对此一无所知 我昨天才真正开始使用 AutoIT 因此示例代码将非常有用,以防您可以给我一个模拟相同功能的示例脚本会很棒:)
    猜你喜欢
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多