Reputation: 3159
I am trying to simulate the functionality of automating right click of a mouse on a specific file or a folder in windows explorer and this is the code snippet I have written to simulate that :
#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)
but this returns me an error saying this :
"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) : ==> Subscript used on non-accessible variable.: MouseClick("Right", $aClient[0] + $aPos[0] + 4, $aClient[1] + $aPos[1] + 4) MouseClick("Right", $aClient^ ERROR Exit code: 1 Time: 1.593
Can anyone suggest me a workaround as to how to address this problem of simulating right clicking using AutoIT.
Upvotes: 1
Views: 2563
Reputation: 2946
For your second question:
These are the function you need. Fiddle with them and you will figure it out.
#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
Upvotes: 1
Reputation: 2946
Try this:
#include<GUIListView.au3>
Local $filepath = "C:\Windows\addins"
Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
ProcessWait($iPid)
Sleep(1000)
Send('+{F10}')
Upvotes: 4