Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ControlClick to 1 Window (where I have same name windows)


  • Please log in to reply
9 replies to this topic
TheRedTerror
  • Members
  • 25 posts
  • Last active: Jul 19 2012 12:51 AM
  • Joined: 19 Jul 2012
Sorry if subject is confusing. I was wondering how would I go about using ControlSend or ControlClick to a specific Window where I have multiple of the same name window open.

Example: Multiple World of Warcraft screens open and I want to send specific commands to the one on the right, but it's being sent to the left.

I'm not after sending the command to every window, I just want to be able to ControlSend commands to each window individually.

(Example from girlgamer)

WinGet, winID, List, Warcraft ;
Loop %winID% ;
{    thisid := winID%A_Index% ;
     str = %str%,%thisid%`n
}

(Example from Spawnova)

settitlematchmode 2
f1::    ;to test
mousegetpos,x,y
ControlClick,x%x% y%y%,Diablo III,,,,pos
return

So if I can read out the winID and put them into a message box to be displayed. Is there a way to separate that information and be able to call it individually and have the control click or control send, send it to a specific window?

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
For multiple windows that have the same titles, you can use the ahk_id window identifier to target a specific window. gamers who multi-box use a method like this a lot as an example consider this...
SetTitleMatchMode, 2
CoordMode, pixel, screen
Coordmode, mouse, screen
DetectHiddenWindows, On

; Hover over one of the windows
SoundBeep, 750
tooltip, place mouse over the window you want to identify. press middle mouse button, 100, 0 
; press the middle mouse button to identify that window
keywait, MButton, D
keywait, MButton
mousegetpos, w1mx, w1my, w1id
; then get the window title from the id
wingettitle, w1title, ahk_id %w1id%
msgbox,0x1020, , This window's id and title are`nId:`t%w1id%`ntitle:`t%w1title%
; with that title find all windows that match that title 
WinGet, winlist, List, %w1title%
; make a displayable string showing the list of ids
str =
loop %winlist%
{    thisid := winlist%A_Index%
     str = %str%`n%thisid%
}
msgbox, Number of matching windows = %winlist%%str%
; then to use any window in the list you simply activate it using it's id
If (winlist)
{	random, thiswin, 1, %winlist% ;<-- pick a random window from the list
	wid := winlist%thiswin%
	msgbox,0x1020,,Activating window#: %thiswin% id: %wid%
	winactivate, ahk_id %wid%
	controlclick,,ahk_id %wid%
}
exitapp

You can test this method by opening multiple autohotkeyhelp windows since they all have the same title when on the screen. open 5 or 6 of them to get a good random sample. this routine will pick one to activate. to send to the window when it's still in the background use controlsend or control click with the id the same way.

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


TheRedTerror
  • Members
  • 25 posts
  • Last active: Jul 19 2012 12:51 AM
  • Joined: 19 Jul 2012
Would it be more beneficial for me to save each ahk_ID seperately and just call them individually as I need them?

For instance: I need to do a series of actions on one window and then a series on another and etc.
I was wondering if it was possible to turn each of the winID's into a string themselves that I could call later on with a say ControlClick or Send so that way AHK knows that I want it to use a specific window to do a specific action.

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
yes you could do that. You can assign, just for example, a char name to a given window -- depending on which character is the likely focus of that window.
healerwin = ahk_id %winid1%
fighterwin = ahk_id %winid2%
magewin = ahk_id %winid3%
johnnyb = ahk_id %winid4%

controlsend, , 123, %fighterwin%
controlsend, , 456, %healerwin%
controlsend, , 143, %magewin%
controlsend, , 1111, %johnnyb%

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


TheRedTerror
  • Members
  • 25 posts
  • Last active: Jul 19 2012 12:51 AM
  • Joined: 19 Jul 2012
Thank's a lot girlgamer. This helps me out so much. ^_^

One last question though if you don't mind.

I'm still fairly new to scripting as the last time I did it was in High School. The above variables you have made that I can call on when I want to use ControlSend or Click later on. How will I be able to separate the correct window to the correct character? Would I simply use something similar to the above to click each window to identify which is which?
Or is there a different way that I may not be noticing?

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
one very straightforward way is to use your mouse to identify the right windows to name. something like this maybe. thefollowing code assumes you're not in full screen mode for any window. it uses an input box to help you id the right windows
#SingleInstance, Force
#Persistent
#MaxThreadsPerHotkey 2
SetTitleMatchMode, 2
SetBatchLines, -1
SetKeyDelay, 50,50
DetectHiddenWindows, On
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
;SendMode, Event

SetTitleMatchMode, 2
CoordMode, pixel, screen
Coordmode, mouse, screen

; Hover over one of the windows
SoundBeep, 750
tooltip, place mouse over the window you want to identify. press middle mouse button, 100, 0 
; press the middle mouse button to identify that window
keywait, MButton, D
keywait, MButton
mousegetpos, w1mx, w1my, w1id
; then get the window title from the id
wingettitle, w1title, ahk_id %w1id%
msgbox,0x1020, , This window's id and title are`nId:`t%w1id%`ntitle:`t%w1title%
; with that title find all windows that match that title 
WinGet, winlist, List, %w1title%
; make a displayable string showing the list of ids
str =
loop %winlist%
{    thisid := winlist%A_Index%
     str = %str%`n%thisid%
}
msgbox, Number of matching windows = %winlist%%str%
; then to use any window in the list you simply activate it using it's id
;If (winlist)
;{	random, thiswin, 1, %winlist% ;<-- pick a random window from the list
;	wid := winlist%thiswin%
;	msgbox,0x1020,,Activating window#: %thiswin% id: %wid%
;	winactivate, ahk_id %wid%
;	click
;}

[color=#FF0000]str =
Loop %winlist% ;<-- used from the example i posted earlier
{   thisid := winlist%A_Index% ; gets the id
     thisid = ahk_id %thisid%
    winactivate, %thisid%
    Inputbox, choice, ,what name do you want to give this window?
    If (Errorlevel) ;<-- cancel was pressed
    {   choice = NoName%A_Index%
    }
    %choice% = %thisid%
	str = %str%name: %choice%`tid:%thisid%`n
}
msgbox,0x1020,, You chose`n`n%str%`n for your window names
ListVars ;<-- shows the list of variables in the script
pause
exitapp[/color]

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


TheRedTerror
  • Members
  • 25 posts
  • Last active: Jul 19 2012 12:51 AM
  • Joined: 19 Jul 2012
Thank you so much girlgamer. I will try this out immediately. Your help has been greatly appreciated.

annayooo
  • Guests
  • Last active:
  • Joined: --

one very straightforward way is to use your mouse to identify the right windows to name. something like this maybe. thefollowing code assumes you're not in full screen mode for any window. it uses an input box to help you id the right windows

#SingleInstance, Force
#Persistent
#MaxThreadsPerHotkey 2
SetTitleMatchMode, 2
SetBatchLines, -1
SetKeyDelay, 50,50
DetectHiddenWindows, On
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
;SendMode, Event

SetTitleMatchMode, 2
CoordMode, pixel, screen
Coordmode, mouse, screen

; Hover over one of the windows
SoundBeep, 750
tooltip, place mouse over the window you want to identify. press middle mouse button, 100, 0 
; press the middle mouse button to identify that window
keywait, MButton, D
keywait, MButton
mousegetpos, w1mx, w1my, w1id
; then get the window title from the id
wingettitle, w1title, ahk_id %w1id%
msgbox,0x1020, , This window's id and title are`nId:`t%w1id%`ntitle:`t%w1title%
; with that title find all windows that match that title 
WinGet, winlist, List, %w1title%
; make a displayable string showing the list of ids
str =
loop %winlist%
{    thisid := winlist%A_Index%
     str = %str%`n%thisid%
}
msgbox, Number of matching windows = %winlist%%str%
; then to use any window in the list you simply activate it using it's id
;If (winlist)
;{	random, thiswin, 1, %winlist% ;<-- pick a random window from the list
;	wid := winlist%thiswin%
;	msgbox,0x1020,,Activating window#: %thiswin% id: %wid%
;	winactivate, ahk_id %wid%
;	click
;}

[color=#FF0000]str =
Loop %winlist% ;<-- used from the example i posted earlier
{   thisid := winlist%A_Index% ; gets the id
     thisid = ahk_id %thisid%
    winactivate, %thisid%
    Inputbox, choice, ,what name do you want to give this window?
    If (Errorlevel) ;<-- cancel was pressed
    {   choice = NoName%A_Index%
    }
    %choice% = %thisid%
	str = %str%name: %choice%`tid:%thisid%`n
}
msgbox,0x1020,, You chose`n`n%str%`n for your window names
ListVars ;<-- shows the list of variables in the script
pause
exitapp[/color]




Hello girlgamer,

I would like to ask you, that this very cool and useful script, and i tryed out for use just send keys to windows like 3, 4, 5 but for me if i use %ahk_id% or make that name1 = %ahk id% i tested with this and that and not work for me dont sending nothing key to those window,

do i need to type like controlsend, , 123, %fighterwin% or do i need type before %fighterwin% the windows name or what do i do wrong ? >.<
please help me out thank you so much :-)
annayooo

annayooo
  • Guests
  • Last active:
  • Joined: --
ahh i forgot to say,

i just would like to control send in background of like 5 windows with same name and send in each like
TAB *after few sec* 3 *few sec* 4 *few sec* 5 *few sec* space and this all in loop

please can u help me in this autohotkey how shall i do it with same name windows to send these same keys in all of 5 window please ? :)

i really thank you so very much for help m8 :-)
annayooo

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
All that script does is allow you to identify the windows using the ahk_id (which is unique for each window that is currently live on your system).

To use any of those windows you have to either a) make one of the windows active and send to it like normal or B) use ControlClick or ControlSend to send to any window or combination of windows. Similar methods for sending to background windows exist in forum threads relating to World of Warcraft. But one way to send to all the related background windows, using the same id's as above, might be... (as an example)
fnC_SendToAll(key)
{   global ;<-- global makes the winlist array variables visible to the function
    loop %winlist% ;<-- loop through each of the windows found in the list
    {    thisid := winlist%A_Index% ;<-- get the window id
         tooltip, sending %key% to window ahk_id %thisid%, 100, 0 ;<-- tooltip feedback to user
         ControlSend, ,%key%, ahk_id %thisid%
         Sleep, 300 ;<-- give window a chance to respond
    }
    tooltip ;<-- turn off tooltip
}
Remember this is only an example. You will have to massage the code to fit what you need. A similar method can be used to send mouse clicks to background windows using ControlClick
This code has not been tested.

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif