Answer the question
In order to leave comments, you need to log in
How to activate the exe program window and click on the button?
Good afternoon, there are several program windows with the same process name, how can I make each window active in turn and click on the button in the window? does not become active and the button is pressed in another window, but on some it works, tell me how you can make it work always and everywhere, I probably made a mistake somewhere in the script or missed something I
did this exe.bat
FOR /F "tokens=*" %%G IN ('wmic process where name^="game.exe" get ProcessId ^| FINDSTR /v ProcessId ^| FINDSTR /r /v "^$"') DO (
%nircmdc% win activate process /!PIDS!%%G
%nircmdc% sendkeypress f1
TIMEOUT /T 1 /NOBREAK
)
Answer the question
In order to leave comments, you need to log in
So after activating the window, pause after TIMEOUT so that the window has time to receive this activation ...
An example of sending the F1 button to
the Visoal Studio Code window using PowerShell
To work directly with the Windows window API, use the
https://github.com/MVKozlov/Powershell-WindowHelper module . \Modules\WindowHelper "
or in " C:\Users\%Username%\Documents\WindowsPowerShell\Modules\WindowHelper "
# Тут можно импортировать модуль напрямую, если не класть его по вышеуказанным путям
#Import-Module C:\Path\To\Module\WindowHelper.psm1
# Или просто импортировать, если есть в путях (необязательно)
#Import-Module WindowHelper
# Импортируем типы для использования SendKeys
Add-Type -AssemblyName System.Windows.Forms
# Ищем среди всех окон окно с нужным заголовком
$w = Get-ChildWindows | ? { $_.Text -eq 'Visual Studio Code' }
# Клавиши, которые нужно нажимать
# Брать отсюда - https://docs.microsoft.com/ru-ru/dotnet/api/system.windows.forms.sendkeys
$KeySequence = '{F1}'
# Активируем нужное окно
Set-ForegroundWindow $w.Handle
# Небольшая задержка
Start-Sleep -Milliseconds 100
# Посылаем клавиши
[System.Windows.Forms.SendKeys]::SendWait($KeySequence)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question