1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#Leer operaciones desde un fichero #Ejemplo de contenido #Esperar 5 segundos, mover el cursor desde la posición X=O, Y=387 hasta la posición X=413, Y=387 y hacer clic en la posición X=413, Y=387. #Guardar el siguiente contenido sin el carácter # en un fichero llamado acciones.txt #esperar,5 #mover,413,387 #clic,413,387 #Importante: #Sustituir las comillas $MouseEventSig=@' [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); '@ Get-Content F:\power\acciones.txt | %{ $MouseEvent = Add-Type -memberDefinition $MouseEventSig -name "MouseEventWinApi" -passThru $operacion=$_.split(',')[0] $param1=$_.split(',')[1] $param2=$_.split(',')[2] switch($operacion){ 'abrir'{ Start-Process $param1 Start-Sleep -Seconds 5 break } 'escribir'{ [System.Windows.Forms.SendKeys]::SendWait($param1) break } 'clic'{ [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($param1,$param2) $MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0) $MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0) break } 'esperar'{ Start-Sleep -Seconds $param1 break } 'mover'{ for($i=0;$i -ne $param1;$i=$i+1){ Start-Sleep -Milliseconds 10 [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($i,$param2) } break } } } |