Updated delay and SRO Check

This commit is contained in:
Kevin Lukritz
2020-11-09 12:46:37 -06:00
parent a9b76b5835
commit 3dbe43171c

View File

@@ -8,7 +8,7 @@
Add-Type -AssemblyName PresentationFramework Add-Type -AssemblyName PresentationFramework
#Hide Console Window <#Hide Console Window
Add-Type -Name Window -Namespace Console -MemberDefinition ' Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")] [DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow(); public static extern IntPtr GetConsoleWindow();
@@ -20,7 +20,7 @@
$consolePtr = [Console.Window]::GetConsoleWindow() $consolePtr = [Console.Window]::GetConsoleWindow()
[Console.Window]::ShowWindow($consolePtr, 0) > $null [Console.Window]::ShowWindow($consolePtr, 0) > $null
#>
#Talking across runspaces #Talking across runspaces
$Sync = [Hashtable]::Synchronized(@{}) $Sync = [Hashtable]::Synchronized(@{})
@@ -34,16 +34,31 @@
$script = [Powershell]::Create().AddScript({ $script = [Powershell]::Create().AddScript({
Param ($Keys) Param ($Keys)
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class UserWindows {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@
$keys = $keys -split ","
while($sync["x"] -eq 1){ while($sync["x"] -eq 1){
$keys = $keys -split ","
Foreach ($key in $keys){ Foreach ($key in $keys){
if ($sync["x"] -eq 1){
Start-Sleep -Milliseconds 500 $ActiveHandle = [UserWindows]::GetForegroundWindow()
[System.Windows.Forms.SendKeys]::SendWait("{$key}") $Process = Get-Process | ? {$_.MainWindowHandle -eq $activeHandle} | Select-Object -ExpandProperty ProcessName
} Write-Output $Process
if ($sync["x"] -eq 1 -and $Process -eq "sro_client"){
Start-Sleep -Milliseconds 50
[System.Windows.Forms.SendKeys]::SendWait("{$key}")
} }
} }
}
}).AddArgument($Keys) }).AddArgument($Keys)
$runspace = [RunspaceFactory]::CreateRunspace() $runspace = [RunspaceFactory]::CreateRunspace()