Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, December 24, 2015 5:40 PM
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!
All replies (8)
Thursday, December 24, 2015 8:20 PM ✅Answered | 3 votes
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 6:14 PM
No mouse clickies.
https://msdn.microsoft.com/en-us/library/ms171548%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
\(ツ)_/
Thursday, December 24, 2015 6:42 PM
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 7:03 PM | 1 vote
It cannot be done with PowerShell. PowerShell does not yue mouse clicks. It can onlybe done in forms.
\(ツ)_/
Thursday, December 24, 2015 10:18 PM
try here:
HTH
Friday, December 25, 2015 2:07 AM
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 [email protected].
Friday, December 25, 2015 6:31 AM
Thanks for your post Wendy.
Tuesday, August 4, 2020 12:27 AM
Searched and came across this. Confirmed working on Windows 10, PowerShell 7.0.3. Also a lot less code than some other solutions