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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
#Leer operaciones desde un fichero #Ejemplo de contenido #Dibujar y colorear una casa en Paint #Guardar el siguiente contenido sin el carácter # en un fichero llamado accionescasa.txt #abrir,mspaint.exe #principio,450,350 #fin,400,400 #principio,450,350 #fin,500,400 #principio,400,400 #fin,500,400 #esperar,5 #principio,400,500 #fin,500,500 #esperar,5 #principio,400,400 #fin,400,500 #esperar,5 #principio,500,400 #fin,500,500 #colorearrojo,451,380 #colorearmarron,448,446 #Importante: #Sustituir las comillas en la variable $MouseEventSig $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 D:\power\accionescasa.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 } 'clicderecho'{ [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($param1,$param2) $MouseEvent::mouse_event(0x00000008, 0, 0, 0, 0); $MouseEvent::mouse_event(0x00000010, 0, 0, 0, 0); break } 'principio'{ [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($param1,$param2) $MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0) break } 'fin'{ [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($param1,$param2) $MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0) break } 'colorearrojo'{ #Hacer clic en bote de pintura, la posición se puede cambiar, en este caso es 363,155 [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(363,155) $MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0) $MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0) #Hacer clic en el color rojo, la posición se puede cambiar, en este caso es 767,146 [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(767,146) $MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0) $MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0) #Colorear con el bote de pintura una vez obtenido el color en la posición que se indica en el fichero [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 } 'colorearmarron'{ #Hacer clic en bote de pintura, la posición se puede cambiar, en este caso es 363,155 [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(363,155) $MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0) $MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0) #Hacer clic en el color rojo, la posición se puede cambiar, en este caso es 767,146 [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(746,167) $MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0) $MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0) #Colorear con el bote de pintura una vez obtenido el color en la posición que se indica en el fichero [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 } } } |
Contenido del fichero accionescasa.txt
Dibujo de la casa con color