Skip to content

Instantly share code, notes, and snippets.

@lzcjames
Created February 27, 2021 17:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lzcjames/b74f27ae8a21089b7a798d0a24354e88 to your computer and use it in GitHub Desktop.
Save lzcjames/b74f27ae8a21089b7a798d0a24354e88 to your computer and use it in GitHub Desktop.
PowerShell Simulate User Mouse and Keyboard Activity
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