Sign in to follow this  
Followers 0
Michri

Multiple Windows Question

9 posts in this topic

I'm attempting to make a basic script to send a keystroke to a background window.

The problem I am having is, when I run two instances of the same program, it will only send it to the instance which was most recently focused on. I either want to send it to both, or a specific one of the multiple instances - but the only entry I get when using the window info tool is "Handle". Is there anywhere in the ControlSend command that will accept Handle, so I can specify which window? If not, is there another command I should look into using in my script?

Share this post


Link to post
Share on other sites



I'm attempting to make a basic script to send a keystroke to a background window.

The problem I am having is, when I run two instances of the same program, it will only send it to the instance which was most recently focused on. I either want to send it to both, or a specific one of the multiple instances - but the only entry I get when using the window info tool is "Handle". Is there anywhere in the ControlSend command that will accept Handle, so I can specify which window? If not, is there another command I should look into using in my script?

I would ensure that each instance has a different title. Here's one way to do it.

$Title0 = "Title "
$Inst = 0
Do
    $Inst += 1
    $Title = $Title0 & $Inst
Until not WinExists($Title)

$MyGui = GUICreate($Title, ....

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I would ensure that each instance has a different title. Here's one way to do it.

$Title0 = "Title "
$Inst = 0
Do
    $Inst += 1
    $Title = $Title0 & $Inst
Until not WinExists($Title)

$MyGui = GUICreate($Title, ....
I'm somewhat new at this. Could you possibly walk me through what that script will do?

Essentially, my goal is to be able to send a keystroke to one instance of a game, to macro an ability on one character, while I play another character. The window title is the same in both instances of the game, and the only thing that shows up in the window info program is the handle, and window title (which are both the same, and dont seem to be of any use).

Share this post


Link to post
Share on other sites

The way I read it you are trying to use ControlSend with handles.

All "title" parameters in AutoIt accept a few things. Handles are one of them.. So if you just: ControlSend($hWnd,....) you're done. :)

Share this post


Link to post
Share on other sites

The way I read it you are trying to use ControlSend with handles.

All "title" parameters in AutoIt accept a few things. Handles are one of them.. So if you just: ControlSend($hWnd,....) you're done. :)

So, if for example, the window handle was 0x001B05DE (taken from my active firefox window atm), and I want to send the keystroke "0", where would I put it in the handle in the line, exactly?

CODE
ControlSend("", "", "", "0")

Which of the 3 blank areas?

Share this post


Link to post
Share on other sites

So, if for example, the window handle was 0x001B05DE (taken from my active firefox window atm), and I want to send the keystroke "0", where would I put it in the handle in the line, exactly?

CODE
ControlSend("", "", "", "0")

Which of the 3 blank areas?

Title parameter, which is the first.

ControlSend(0x001B05DE, "", "", "0")

Share this post


Link to post
Share on other sites

Title parameter, which is the first.

ControlSend(0x001B05DE, "", "", "0")

No luck. There is no input when I use that method, but it works fine when I use the actual window title.

Share this post


Link to post
Share on other sites

Just to explain:

The handle of a window will be different everytime it is created, so you can't use a static value in your script. Using Manadar's code above will retrieve the handle to a window that exists and if you continue to use this handle (in the $hwnd variable) it will always refer to that specific window.

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