Sign in to follow this  
Followers 0
snj78

Script will only run on the active window

9 posts in this topic

I have a script that will run, but only when the window is active. If i minimize that window to work on other things, it starts running the script on the window that I have active, not the desired window. Also, I have 2 windows with no unique identifiers (everything is the same), how do I run 2 different scripts at the same time and be able to choose which script runs on which window, and have them both running in the background on those windows so that I can work on other things?

Share this post


Link to post
Share on other sites



You need to look up the control command in the help file. Controlsend, Controlclick etc. Here's an example of how it works.

Run("Notepad.exe")
WinWait("Untitled - Notepad")
WinSetState("Untitled - Notepad", "", @SW_MINIMIZE)
ControlSend("Untitled", "", "Edit1", "This is a line of text in the notepad window")

Share this post


Link to post
Share on other sites

Thank you for your reply.

I don't want to use this command because I want to minimize and maximize manually without affecting the script.

WinSetState("Untitled - Notepad", "", @SW_MINIMIZE)

The problem I'm having is that I'm running to clients that are exactly the same. I run the script and it works great when the desired window is active. When I open the other window, it starts to run the script on that window. I have tried to differentiate between the two windows, even changing the window title, but to no avail. There is no text either, that will help to distinquish the two. I think the ControlSend command will work for me, but how do i use that and differentiate between the two windows?

Share this post


Link to post
Share on other sites

try to make a pause hotkey, theres an example on the autoit help file ^^

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Using WinSetTitle Doesn't work? What programs are you running?

And with the WinSetState I was demonstrating how even if the window is minimized it still works.

Edited by bucky002

Share this post


Link to post
Share on other sites

Thanks for replying. The pause key would work to pause the script when I have another window up, but I don't want that script to stop working on that specified window. I want the script to run continuously on the window whether it is the active window or not.

Share this post


Link to post
Share on other sites

I did use WinSetTitle to change the title and try to differentiate between the two windows, but I must not have been doing something right. I am running the game Shadowbane and want the script to run continuously on that window.

After I change the title, which Win* command would allow me to run the script in only that window? The WinActivate or WaitWinActive commands with the new title wouldn't work. The script would still switch to whichever window was the active window at the time.

Thanks a bunch for your help, I am a low level newb programmer and your help is much appreciated.

Share this post


Link to post
Share on other sites

So you are running 2 shadowbane windows right? Are you doing the same thing in each window? Or are you mouseclicking in one and sending keys in other? Will something like this work, you probably already tried this though.

Run("Notepad.exe")
Run("Notepad.exe")
WinWait("Untitled - Notepad")
WinSetTitle("Untitled - Notepad", "", "Notepad")
WinSetState("Notepad", "", @SW_MINIMIZE)
WinSetState("Untitled - Notepad", "", @SW_MINIMIZE)
ControlSend("Untitled - Notepad", "", "Edit1", "Default window")
ControlSend("Notepad", "", "Edit1", "Changed window name")

Share this post


Link to post
Share on other sites

Thanks a ton for your help, that actually solved the problem. I had to change the title in one window, and then use the controlsend function like you suggested. It works no matter what I have going or whether that is minimized or the active window. I am just sending keystrokes to the window to perform certain functions that i set up within the game. Changing the title and using controlsend solved everything. Thanks a ton for your help. Now I can do homework while the game plays without any interference. Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0