none
Mouse Click

    Question

  • I'm looking for mouse click function in powershell script  since last night and i can't find no one that work.

    I have been tried the script from link but don't work. Does anybody some powershell script to simulate mouse left and right click?

    Thanks!

    Thursday, December 24, 2015 5:40 PM

Answers

  • I have a Christmas gift to you, Jrv.

    I keep trying  and its worked!!!!!!! I deleted some lines from old link and it's works man.

    Please, don't try do it in Powershell ISE buttons. Try in a browser e.g.

    Set the cursor position in chrome or iexplorer hyperlink e.g. and it will work

    start iexplore.exe
    
    #Set the average time to your system load and open an iexplorer page
    Start-Sleep -Seconds 3
    
    [system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null
    
    # Set the exactly position of cursor in some iexplore hyperlink between the (open parenthesis) below: 
    [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(1240,489)
    
    function Click-MouseButton
    {
        $signature=@' 
          [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
          public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
    '@ 
    
        $SendMouseClick = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru 
    
            $SendMouseClick::mouse_event(0x00000002, 0, 0, 0, 0);
            $SendMouseClick::mouse_event(0x00000004, 0, 0, 0, 0);
    }
    
    Click-MouseButton

    Enjoy it!

    Thursday, December 24, 2015 8:20 PM

All replies

  • It's not easy to do. 

    Now i know the reason for not found yet a script to do this.

    I will try do this Jrv. Thanks.

    Do you have some script or some documentation simpler than your link above?

    Thanks again

    Thursday, December 24, 2015 6:42 PM
  • It cannot be done with PowerShell.  PowerShell does not yue mouse clicks.  It can onlybe done in forms.


    \_(ツ)_/

    Thursday, December 24, 2015 7:03 PM
    Moderator
  • I have a Christmas gift to you, Jrv.

    I keep trying  and its worked!!!!!!! I deleted some lines from old link and it's works man.

    Please, don't try do it in Powershell ISE buttons. Try in a browser e.g.

    Set the cursor position in chrome or iexplorer hyperlink e.g. and it will work

    start iexplore.exe
    
    #Set the average time to your system load and open an iexplorer page
    Start-Sleep -Seconds 3
    
    [system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null
    
    # Set the exactly position of cursor in some iexplore hyperlink between the (open parenthesis) below: 
    [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(1240,489)
    
    function Click-MouseButton
    {
        $signature=@' 
          [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
          public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
    '@ 
    
        $SendMouseClick = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru 
    
            $SendMouseClick::mouse_event(0x00000002, 0, 0, 0, 0);
            $SendMouseClick::mouse_event(0x00000004, 0, 0, 0, 0);
    }
    
    Click-MouseButton

    Enjoy it!

    Thursday, December 24, 2015 8:20 PM
  • try here:

    AutoIt Script website

    HTH

    Thursday, December 24, 2015 10:18 PM
  • Hi,

    I am glad that it is working for you.

    Thank you for sharing the solution and update.

    Appreciate your great efforts.

    Best regards,


    Please remember to mark the replies as answers if they help and un-mark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, December 25, 2015 2:07 AM
    Moderator
  • Thanks for your post Wendy.
    Friday, December 25, 2015 6:31 AM