Home > Blockchain >  Powershell Looping with Mouse Automation
Powershell Looping with Mouse Automation

Time:10-21

I found a powershell script that does cursor automation for executing events, but I don't know how to put it in a loop without having to manually adjust x and y each time. There is more to the script but the only part changing is the beginning where a selection is being made.

$x = 2870
$y = -640
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
sleep -Seconds 01
$SendMouseClick::mouse_event(0x00000002, 0, 0, 0, 0);
$SendMouseClick::mouse_event(0x00000004, 0, 0, 0, 0);

Desired output would be for $y to be subtracted by 30 about 36x until I switch to the next page. The number 30 was chosen because that is the distance between the list of selections. Would changing $y interfere with the rest of the script where I have specific locations for my cursor?

CodePudding user response:

You can do this with a For loop pretty simply. You want to set your initial coordinates, then just adjust $y on each iteration.

$x = 2870
$y = -640
for($i=0;$i -lt 36;$i  ){
    [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, ($y-$i*30))
    sleep -Seconds 01
    $SendMouseClick::mouse_event(0x00000002, 0, 0, 0, 0);
    $SendMouseClick::mouse_event(0x00000004, 0, 0, 0, 0);
}
  • Related