PowerShell Simulate User Mouse and Keyboard Activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -AssemblyName System.Windows.Forms | |
# import mouse_event from user32.dll | |
Add-Type -MemberDefinition '[DllImport("user32.dll")] public static extern void mouse_event(int flags, int dx, int dy, int cButtons, int info);' -Name u32func -Namespace w; | |
function mouseMvClik($x, $y){ | |
# mouse move | |
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x,$y) | |
# left mouse click up | |
[w.u32func]::mouse_event(0x00000002, 0, 0, 0, 0); | |
# left mouse click down | |
[w.u32func]::mouse_event(0x00000004, 0, 0, 0, 0); | |
} | |
function saisirUnChamp($code, $type, $obl, $description){ | |
mouseMvClik 742 247 | |
sleep -Seconds 1 | |
[System.Windows.Forms.SendKeys]::SendWait($code) | |
sleep -Seconds 1 | |
$firstChar = $type.substring(0, 1) | |
switch ($firstChar) { | |
"V" { | |
mouseMvClik 500 464 | |
[System.Windows.Forms.SendKeys]::SendWait($type) | |
isRequired($obl) | |
break | |
} | |
"D" { | |
mouseMvClik 490 400 | |
sleep -Seconds 1 | |
mouseMvClik 404 430 | |
sleep -Seconds 1 | |
mouseMvClik 782 416 | |
[System.Windows.Forms.SendKeys]::SendWait("d") | |
mouseMvClik 744 433 | |
sleep -Seconds 1 | |
mouseMvClik 500 464 | |
[System.Windows.Forms.SendKeys]::SendWait($type) | |
isRequired($obl) | |
break | |
} | |
"N" { | |
mouseMvClik 490 400 | |
sleep -Seconds 1 | |
mouseMvClik 404 445 | |
sleep -Seconds 1 | |
mouseMvClik 782 416 | |
sleep -Seconds 1 | |
[System.Windows.Forms.SendKeys]::SendWait("n") | |
sleep -Seconds 1 | |
mouseMvClik 744 433 | |
sleep -Seconds 1 | |
mouseMvClik 500 464 | |
sleep -Seconds 1 | |
[System.Windows.Forms.SendKeys]::SendWait($type) | |
isRequired($obl) | |
break | |
} | |
default {"type not found"; break} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment