I am new to powershell and I'm trying to write an autoclicker. So far I have this code:
Add-Type -MemberDefinition '[DllImport("user32.dll")] public static extern void mouse_event(int flags, int dx, int dy, int cButtons, int info);' -Name U32 -Namespace W;
function click {
[W.U32]::mouse_event(2,0,0,0,0);
[W.U32]::mouse_event(4,0,0,0,0);
}
$i = 10
while ($i -ge 0) {
Write-Host "$i clicks remaining"
Start-Sleep -m 1000
click
Write-Host "Clicked!"
$i -= 1
}
The problem is that when I run the script it only performs the first click and then it just hangs.
The output is just:
10 clicks remaining
Only when I press Ctrl+C the script advances to the next iteration of the loop.
10 clicks remaining
Clicked!
9 clicks remaining
I simply don't understand what I'm doing wrong.