#Hook into sub window. Specifically detect when subwindow opens.

1 messages · Page 1 of 1 (latest)

zealous totem
#

Hello. SO:

I am currently trying to hook into a sub window of a process. That separate window does not have a separate subprocess.

Basically all I'm trying to do is press enter when the subwindow pops up lol.

Here are the snippets i already have from the main script which hook into the main process detecting title name changes.

while ($true) {
        $title = New-Object System.Text.StringBuilder 256
        [WindowHelper]::GetWindowText($xEditProcess.MainWindowHandle, $title, $title.Capacity) | Out-Null
        $title = $title.ToString()

        if ($title -match "FO4Script") {
            Write-Output "Title change detected (indicates script is complete) Closing..."
            $xEditProcess.CloseMainWindow()
            $xEditProcess.WaitForExit()
            break
        }

        Start-Sleep 1
    }
if (-not ('WindowHelper' -as [Type])) {
    Add-Type -TypeDefinition @"
    using System;
    using System.Runtime.InteropServices;
    using System.Text;

    public struct INPUT
    {
        public uint Type;
        public KEYBDINPUT Data;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct KEYBDINPUT
    {
        public ushort wVk;
        public ushort wScan;
        public uint dwFlags;
        public uint time;
        public IntPtr dwExtraInfo;
    }

    public class WindowHelper {
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

        [DllImport("user32.dll")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        public static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
    }
"@
}

I also attached the main script this is going in.

wary echo
#

On first blush, I would expect AutoIT or AutoHotKey to be used with this to automate keyboard and mouse. Super ugly. Maybe you can make the window active and do ALT + F4.

tough flame
tough flame
#

Although (since I wrote WASP), I've never used it 😉