Script restricting to one instance of a program + running in background
Script restricting to one instance of a program + running in background
Hey i was struggling to create an Script. Im currently having 2 instances open of the same program but i do only wanna let the script target one of those 2 instances. I want this script to perform actions in this secondary Program-instance, while the targeted Instance is running in the background, but i guess its gonna happen if the target is restricted to the one instance anyway. Can anyone help with this issue?
Re: Script restricting to one instance of a program + running in background
i have no idea what ure saying
no code + vague description = no one cares about thread
no code + vague description = no one cares about thread
Re: Script restricting to one instance of a program + running in background
I'm not sure what exactly you're asking. If you could provide sample code that would help.
However to uniquely target a specific app, you can use the windows unique hwnd.
Here is a small demo showing how to use unique Handles:
Also if it's an app without a window (like another ahk instance) you can try setting
Hope this helps!
However to uniquely target a specific app, you can use the windows unique hwnd.
Here is a small demo showing how to use unique Handles:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines -1
#SingleInstance Force
SetTitleMatchMode 2 ; A window's title can contain WinTitle anywhere inside it to be a match.
Run notepad
Sleep 500
WinGet, Hwnd, ID , Notepad ; https://www.autohotkey.com/docs/commands/WinGet.htm#ID
Hwnd:="ahk_id " ID
; Alternatively...WinExist(WinTitle) also captures the unique Hwnd
Hwnd:="ahk_id " WinExist("Notepad")
WinActivate % Hwnd ; Hwnd is unique to this notepad instance.
ControlSend, Edit1, This Handle ( %Hwnd% ) is unique to this notepad instance.{Enter}, %Hwnd%
WinMinimize, % Hwnd
Run notepad,,,PID
Sleep 500
Hwnd2:="ahk_id " WinExist("ahk_pid " PID)
ControlSend, Edit1, This Handle ( %Hwnd2% ) is also unique to this specific notepad instance. {Enter}, %Hwnd2%
WinActivate % Hwnd
WinMove % Hwnd,,% (A_ScreenWidth//4),% (A_ScreenHeight//2) ,% (A_ScreenWidth//4), % (A_ScreenHeight//3)
WinActivate % Hwnd2
WinMove % Hwnd2,,% (A_ScreenWidth//2),% (A_ScreenHeight//2) ,% (A_ScreenWidth//4), % (A_ScreenHeight//3)
WinActivate % Hwnd
Send I {Enter}
WinActivate % Hwnd2
Send Can{Enter}
WinActivate % Hwnd
Send Easily {Enter}
WinActivate % Hwnd2
Send Switch {Enter}
WinActivate % Hwnd
Send Between {Enter}
WinActivate % Hwnd2
Send Each {Enter}
WinActivate % Hwnd
Send Instance {Enter}
ExitApp
Escape::ExitApp
Code: Select all
DetectHiddenWindows On
Re: Script restricting to one instance of a program + running in background
Lets say it like that: I have 2 documents of Wordpad open. One is selected, one minimized. I want the AHK script to press buttons to the minimized one. Ive been trying out a bit with IfWinNotActive, but i got the feeling that not the right command for that, more for "performing actions if Wordpad is not open at all".
That for now works for the selected window of Wordpad, but idk how to go on for checking for the unselected wordpad-window.
Code: Select all
*f3::
toggle := !toggle
if (toggle) {
SetTimer, Spam_Space, 10
} else {
SetTimer, Spam_Space, Off
}
return
Spam_Space:
SendInput {Space}
return
Re: Script restricting to one instance of a program + running in background
find the hwnds of both windows(use WinExist())
use ControlSend to send keys to the second window using the second window's hwnd
use ControlSend to send keys to the second window using the second window's hwnd
Re: Script restricting to one instance of a program + running in background
Ok figured it out.
Thank you so much swagfag & Tensai for your help ^^
Thank you so much swagfag & Tensai for your help ^^