Search code examples
powershellclicksendkeys

Powershell Mouseclick Dialog Box


I am writing a script to use winzip from powershell but I am having problems clicking the mouse inside the address bar of a dialog box.

I have solved the problem using the 7zip method but I want to learn another method.


(I have 2 screens hence the coordinates of the mouse). I tried making a new shell just for the dialog box but that doesn't work. What am I doing wrong?

UPDATE: When I put the Sleep 1 in front of the click, the computer makes a tone. Am I dealing with a focus issue?

Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$screen | Get-Member -MemberType Property
$Width=$screen.Width
$height=$screen.Height


& "C:\Program Files (x86)\WinZip\WINZIP32.EXE"
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Winzip Pro')
Sleep 1
$wshell.SendKeys('% ')
$wshell.SendKeys('x')
$wshell.SendKeys('%')
$wshell.SendKeys('o')
$wshell.SendKeys('p')

[Windows.Forms.Cursor]::Position = "2600,40"
Sleep 1
$wshell.SendKeys( {ClickLeft})

#$Dialog = New-Object -ComObject wscript.shell;
#$Dialog.AppActivate('Zip')
#Sleep 1
#$Dialog.Sendkeys({ClickLeft})

Solution

  • I figured out how to zip the file using the mouse and not through the 7zip command interface.

    The first step was to copy in the function seen in the top answer for this question power shell : how to send middle mouse click?

    Whenever I want the mouse to click, I script in Click-MouseButton -button left

    in place of left, one can also type in right or middle

    Then it is a matter of sending the strings containing paths and names and moving and clicking the mouse.