59 lines
4.3 KiB
PowerShell
59 lines
4.3 KiB
PowerShell
# drv_splitter_mouse.ps1 [-Poz <n>|-] [-Desch <k>] - tragere REALA cu mouse-ul pe splitterul din frm_import_efactura (modal, ca in aplicatie).
|
|
# Porneste test_splitter_mouse.prg in mod E; VFP scrie coordN.txt, driverul misca mouse-ul (SetCursorPos + mouse_event).
|
|
# -Desch k: formularul se deschide de k ori in aceeasi sesiune VFP (semnalele fiecarei deschideri in sync_mouse\d<i>).
|
|
param([string]$Poz = '0', [int]$Desch = 1, [int]$Dx = 0)
|
|
$dir = 'D:\ROA\ROACONT\COMUN\utile\Teste\efactura_import'
|
|
$syncBaza = Join-Path $dir 'sync_mouse'
|
|
$prg = Join-Path $dir 'test_splitter_mouse.prg'
|
|
$log = Join-Path $dir 'test_splitter_mouse_log.txt'
|
|
New-Item -ItemType Directory -Force $syncBaza | Out-Null
|
|
Get-ChildItem $syncBaza -Recurse -File | Remove-Item -Force
|
|
foreach ($f in @('test_splitter_mouse.FXP','test_splitter_mouse.ERR','test_splitter_mouse_temp.ini')) { $p = Join-Path $dir $f; if (Test-Path $p) { Remove-Item $p -Force } }
|
|
Start-Process powershell -ArgumentList @('-ExecutionPolicy','Bypass','-File','D:\ROA\ROACONT\COMUN\utile\Teste\_precompile.ps1','-Prg',$prg) -Wait -WindowStyle Hidden
|
|
if (Test-Path (Join-Path $dir 'test_splitter_mouse.ERR')) { Get-Content (Join-Path $dir 'test_splitter_mouse.ERR'); exit 2 }
|
|
Add-Type @"
|
|
using System; using System.Runtime.InteropServices;
|
|
public class MDrv {
|
|
[DllImport("user32.dll")] public static extern bool SetCursorPos(int x,int y);
|
|
[DllImport("user32.dll")] public static extern void mouse_event(int f,int x,int y,int d,int e);
|
|
[DllImport("user32.dll")] public static extern short GetAsyncKeyState(int v);
|
|
[DllImport("user32.dll")] public static extern IntPtr WindowFromPoint(POINT p);
|
|
[DllImport("user32.dll")] public static extern IntPtr GetAncestor(IntPtr h,int f);
|
|
[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; }
|
|
}
|
|
"@
|
|
function Asteapta([string]$f, [int]$ms = 20000) { $t = 0; while (-not (Test-Path (Join-Path $sync $f))) { Start-Sleep -Milliseconds 100; $t += 100; if ($t -ge $ms) { return $false } }; return $true }
|
|
function Semnal([string]$f) { Set-Content -Path (Join-Path $sync $f) -Value 'ok' }
|
|
function Trage([int]$x, [int]$y, [int]$dy) {
|
|
[MDrv]::SetCursorPos($x, $y) | Out-Null; [MDrv]::mouse_event(2,0,0,0,0); Start-Sleep -Milliseconds 150
|
|
for ($i = 1; $i -le 12; $i++) { [MDrv]::SetCursorPos($x, $y + [int]($dy * $i / 12)) | Out-Null; Start-Sleep -Milliseconds 40 }
|
|
Start-Sleep -Milliseconds 100; [MDrv]::mouse_event(4,0,0,0,0); Start-Sleep -Milliseconds 300
|
|
}
|
|
$p = Start-Process 'C:\Program Files (x86)\Microsoft Visual FoxPro 9\vfp9.exe' -ArgumentList @('-A','-T',"`"$prg`"",$Poz,'E',"$Desch") -WorkingDirectory 'D:\ROA\ROACONT' -PassThru
|
|
try {
|
|
:deschideri foreach ($d in 1..$Desch) {
|
|
$sync = Join-Path $syncBaza "d$d"
|
|
New-Item -ItemType Directory -Force $sync | Out-Null
|
|
foreach ($n in 1..3) {
|
|
if (-not (Asteapta "coord$n.txt" 90000)) { "d$d fara coord$n"; break deschideri }
|
|
$c = (Get-Content (Join-Path $sync "coord$n.txt")).Split(','); $x = [int]$c[0] + $Dx; $y = [int]$c[1]; $root = [int64]$c[2]
|
|
$pt = New-Object MDrv+POINT; $pt.X = $x; $pt.Y = $y
|
|
$sub = [MDrv]::GetAncestor([MDrv]::WindowFromPoint($pt), 2).ToInt64()
|
|
if ($sub -ne $root) { "ABANDON: sub punctul $x/$y e fereastra $sub, nu forma $root"; break deschideri }
|
|
[MDrv]::SetCursorPos($x, $y + 200) | Out-Null; Start-Sleep -Milliseconds 500
|
|
if ($n -eq 1) { Add-Type -AssemblyName System.Drawing; $bmp = New-Object System.Drawing.Bitmap 920, 60; $g = [System.Drawing.Graphics]::FromImage($bmp); $g.CopyFromScreen($x - 35, $y - 30, 0, 0, $bmp.Size); $bmp.Save((Join-Path $dir "splitter_repaus_Poz${Poz}_d$d.png")); $g.Dispose(); $bmp.Dispose() }
|
|
Semnal "repaus$n.txt"; if (-not (Asteapta "repausok$n.txt")) { "d$d fara repausok$n"; break deschideri }
|
|
if ($n -eq 3) { break }
|
|
[MDrv]::SetCursorPos($x, $y) | Out-Null; Start-Sleep -Milliseconds 500
|
|
Semnal "hover$n.txt"; if (-not (Asteapta "hoverok$n.txt")) { "d$d fara hoverok$n"; break deschideri }
|
|
Trage $x $y $(if ($n -eq 1) { -60 } else { 60 })
|
|
Semnal "done$n.txt"
|
|
}
|
|
}
|
|
if (-not $p.WaitForExit(60000)) { $p.Kill(); 'TIMEOUT - proces omorat' }
|
|
} finally {
|
|
if ([MDrv]::GetAsyncKeyState(1) -lt 0) { [MDrv]::mouse_event(4,0,0,0,0); 'buton stang eliberat' }
|
|
if (-not $p.HasExited) { $p.Kill(); 'proces omorat' }
|
|
}
|
|
Get-Content $log
|