Jump to content

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

Mirroring current location clicks in all same-name windows


  • Please log in to reply
9 replies to this topic
Reidmere
  • Members
  • 5 posts
  • Last active: Feb 10 2013 02:52 AM
  • Joined: 07 Feb 2013

Hi, I'm completely new to this, and honestly only got this for one purpose, which I haven't been able to figure out how to do yet... I'm trying to figure out how I can make it so that if I left/right click a location on the current window, that it copies the mouse location to the other windows of the same name.

 

I can declare the name of the window, it doesn't have to be "universal" to pick up the current window name:
I simply want it so if I left or right click my character on this game window, it will do the same thing on the other.
In short, I'm wanting to do something like set Attacks on my main window for one class, but then having the second character with a difference class follow heel to toe with me (which is why I want the left click copy), and to use his attack when right-click the target.

 

Is this feasible in AHK, and if so, could someone give me the code, and LIGHTLY explain what the blocks mean, more or less? I'm still pretty new to macro recording, and have just mainly recorded them before... Thanks!



JadeDragon
  • Members
  • 935 posts
  • Last active: Jun 07 2014 07:40 AM
  • Joined: 18 Jan 2013

Ok if I understand you right you are trying to multi-box at least two windows with the same "name". Essentially you're running two (or more) instances of the same program that you want to send clicks to. Is this correct? If so then it may be possible to send clicks to both with the ControlClick command. Some windows respond to that others don't so your mileage may vary.

The theory behing multiboxing multiple windows under AutoHotkey involves finding the unique instance identifiers for the windows you want to control and saving those in some kind of list. Once you have that you may be able ControlSend keys to those windows or ControlClick mouse clicks to them.The important commands you need to accomplish this magic are:

  • WinGet: WinGet, OutputVar [, Cmd, WinTitle, WinText, ExcludeTitle, ExcludeText]
  • ControlClick: ControlClick [, Control-or-Pos, WinTitle, WinText,WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText]
  • ControlSend:

    ControlSend [, Control, Keys, WinTitle, WinText,ExcludeTitle, ExcludeText]

And some commands to support those like

  • Loop
  • If
  • Break
  • SetTitleMatchMode

An example (and only an example) of how this might be done using World of Warcraft would be

; Note: this is just an example of how it could be done. I make no guarantee
; that it will work for what you need. 
SetTitleMatchMode, 2
CoordMode, Pixel, Relative
CoordMode, Mouse, Relative
CoordMode, Tooltip, Relative

WinGet, vWinList, List, Warcraft ;<-- change Warcraft to the name of window you want to send to

^f1:: <-- ctrl-f1 tries to send control clicks to the target windows one left click one right click
Loop, %vWinList%
{   tid := vWinList%A_Index%
    tx = 50 ;<-- sending to x=50 y=50
    ty = 50
   controlclick, x%tx% y%ty%, ahk_id %tid%,,left,1
   sleep 300
   controlclick, x%tx% y%ty%, ahk_id %tid%,,right,1
   sleep 300
}
Return

^Esc::ExitApp ;<-- use ctrl-esc to end the script

I strongly recommend you run whatever game you're trying to control in windowed mode not Fullscreen mode. In general, Fullscreen mode responds poorly to automation attempts. Some game windows also while responding to ControlSends simply refuse to acknowledge ControlClick commands. You'll have to check your game for it's ability to handle what you intend to do.


Never assume evil intent when simple ignorance will suffice. Ignorance is an eventually curable condition with the right education. Evil intent, however, is another matter entirely. Scripts are much like children. Simple to conceive. Difficult, expensive, and time-consuming to raise. Often do the opposite of what you expect them to. Require frequent  "correction". And once they leave home you can't control them anymore. But you love them anyway.


Reidmere
  • Members
  • 5 posts
  • Last active: Feb 10 2013 02:52 AM
  • Joined: 07 Feb 2013

Thanks for the response.
Yes, I'm trying to get all the same-named windows to recognize the same clicks and locations of those clicks.

I must say though, I'm kind of confused when it comes to what you're saying about the "ControlSend" and PIDs.
I did read (at least most of) the beginner tutorial, but I'm completely unfamiliar with who to use/active ControlSend.
Also, from the tutorial, it gave examples using specific window names (Untitled - Notepad).
Is there a reason I can't just have it effect the name of the game (same dir), since I want all to do the same thing, not excluding one?

I thank you for the example, but I don't really know how to make heads or tails of the variables to adjust it, or find the PID you're speaking of.
I have a bit of experience with coding, specifically CSS, PHP, and a little C++, but don't know what to do with this...

In short, what it looks like to me, is that it's telling it to get the PID of the game (but I don't see how it's stored or referenced),
Tells ONE window to click x:50;y:50... but I want to hit ALL windows, and at the CURRENT location of the mouse
(current x;y on the InFocus window, not current x:y; on every window, clicking the background mice to the InFocus window's X;Y coords).
Sorry if that's not very clear, I just woke up and am doing what I can, after a disturbing dream, lol....

So if you could clarify, if that's what the programming does, what I'm missing, I'd appreciate it;
and/or getting a copy of the code that would work "let's say using the window name "Warcraft" as above.
I prefer not to use the game name, because I'm not sure if they're accepting of multiboxing, especially on one CPU.

Thanks a lot for your time! ^_^



JadeDragon
  • Members
  • 935 posts
  • Last active: Jun 07 2014 07:40 AM
  • Joined: 18 Jan 2013
it's actually pretty simple. Every program that gets run on a windows computer receives two identifiers one is called the process id (the ahk_PID) and one is called the instance id (ahk_ID). If a program has a window, the instance ID can be found using that window and from that the name of the window can be found as well. If the window of a program is active the ID and it's name can be found like this...
WinGet, vWinID, ID, A ;<-- get the window ID of the active window
WinGetTitle, vWinTitle, ahk_id %vWinID% ;<-- use the ahk_id of the window to find it's name
WinGet, vWinPID, PID, A ;<-- get the process ID of the program 
MsgBox, Window ID: %vWinID%`nWindow Title: %vWinTitle%`nProcess ID: %vWinPID%
Although there can be multiple windows on-screen that have the same names each of them has a different identifier so the system can keep track of them. The key to using the IDs effectively is to make sure you save them so you can refer to them individually as you need to when running your script. In a game for example, you might have one window that shows your warrior character and in the other you have your healer. In many games you need two different accounts just to do this but once you do have those accounts you can play both characters at the same time. That's called multi-boxing (in this case two-boxing). Using the separate window ID's for each of those character's windows, even though the names of the windows may be the same, you can control each character individually from the same script. If you needed to get the IDs for multiple windows of the same game you can get it like this...
; after getting the Id of that active window like we did in the above example...
SetTitleMatchMode, 2 <-- allow the use of abbreviated window titles
WinGet, vWinList, List, %vWinTitle% ;<-- get a list of all windows with that title;
; at this point vWinList contains the number of windows found that have that title
; we'll make a list of the windows that we can display with a message box
txtlist =
Loop, %vWinList% ;<-- for each window ID in the list...
{   awin := vWinList%A_Index% ;<- pull out a copy of the next window's id
    txtlist = %txtlist%%awin%`n ;<-- put the id into txtlist for the message box with a linefeeed
} 
MsgBox, The window Id's were`n%txtlist%
To use those ID's then to control your game you'd use the ControlSend and ControlClick commands to send keys and mouse clicks to the game windows with the ID of the window you wanted to send to.

Never assume evil intent when simple ignorance will suffice. Ignorance is an eventually curable condition with the right education. Evil intent, however, is another matter entirely. Scripts are much like children. Simple to conceive. Difficult, expensive, and time-consuming to raise. Often do the opposite of what you expect them to. Require frequent  "correction". And once they leave home you can't control them anymore. But you love them anyway.


Reidmere
  • Members
  • 5 posts
  • Last active: Feb 10 2013 02:52 AM
  • Joined: 07 Feb 2013

Thing is, I'm not looking to control each one individually, I want to control both/all with mouse clicks.
Think is, I don't know how to send mouse x/y to the background instance(s), nor the clicks...



JadeDragon
  • Members
  • 935 posts
  • Last active: Jun 07 2014 07:40 AM
  • Joined: 18 Jan 2013
I think we're missing each other here. To control all windows you have to be able to control EACH window. You'd just group the commands so they shoot at each window separately but sequentially. See my first example in this thread for how you'd control multiple Warcraft windows. AutoHotkey is an assault rifle not a shotgun.

Never assume evil intent when simple ignorance will suffice. Ignorance is an eventually curable condition with the right education. Evil intent, however, is another matter entirely. Scripts are much like children. Simple to conceive. Difficult, expensive, and time-consuming to raise. Often do the opposite of what you expect them to. Require frequent  "correction". And once they leave home you can't control them anymore. But you love them anyway.


Reidmere
  • Members
  • 5 posts
  • Last active: Feb 10 2013 02:52 AM
  • Joined: 07 Feb 2013

I understand what you're saying there, but here's what I'm getting:

 

"WinGet, vWinList, List, Warcraft" <--- links to ---> ^f1:: Loop, %vWinList%"

Then...
tid := vWinList%A_Index%

tx = 50 ; ty = 50 ; <---declared variable, not set from click on current window, right?


controlclick, x%tx% y%ty%, ahk_id %tid%,,left,1 <--NO CLUE
sleep 300 <---pause 0.3s
controlclick, x%tx% y%ty%, ahk_id %tid%,,right,1 <--NO CLUE
sleep 300 <---pause 0.3s

So basically I don't know how to have the CURRENT mouse X/Y apply to the other %vWinList% items before sending a click over.
I essentially want to click ALL overlapping windows (instances of that game declared in vWinList) with the same location and click.



MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

Hi Reidmere.

I have not read the previous posts entirely, and I apologize in advance for that.

However, I noticed you may be interested in multiboxing (for WoW or simply Warcraft maybe).

In that case, you should probably google "multiboxing wow site:autohotkey.com" (I tried it and some interesting results showed up).

Perhaps what you're trying to achieve has already been scripted (I remember other people requesting the same thing). happy.png


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio Fran├ža -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Reidmere
  • Members
  • 5 posts
  • Last active: Feb 10 2013 02:52 AM
  • Joined: 07 Feb 2013

Thanks Master, but it's not for warcraft, it's for another game... I wouldn't yet know how to adjust some scripts for what I want to do.

Long story short, I want to click all windows with a left and right click, exactly where I'm clicking it in the main, so the alt characters will follow.



JadeDragon
  • Members
  • 935 posts
  • Last active: Jun 07 2014 07:40 AM
  • Joined: 18 Jan 2013
  1. In your script, set the following
  2.    CoordMode, Mouse, Relative
  3.    CoordMode, Pixel, Relative
  4.    CoordMode, Tooltip, Relative
  5. Run all the game windows that you intend to
  6. Grab the ahk iD's for each of those windows by following the examples I showed you before
  7. Activate the main character's window
  8. Create hotkeys for LButton and RButton separately
  9. In those hotkey definitions once the button is clicked
  10.    MouseGetPos, mx, my
  11.    Loop through each of your saved Instance ID's
  12.       Use mx and my from the main window in your ControlClick command for the target Window ID
  13. then exit your hotkey
    ; sample hotkey for the LButton
    LButton::
       MouseGetPos, mx, my
       loop, %vWinList%
       {   awinID := vWinList%A_Index%
           ; prototype for command ControlClick [, Control-or-Pos, WinTitle, WinText,WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText]
           ControlClick, x%mx% y%my%, ahk_ID %awinID%,,Left, 1
           Sleep 200
       }
       Return
    

     


Never assume evil intent when simple ignorance will suffice. Ignorance is an eventually curable condition with the right education. Evil intent, however, is another matter entirely. Scripts are much like children. Simple to conceive. Difficult, expensive, and time-consuming to raise. Often do the opposite of what you expect them to. Require frequent  "correction". And once they leave home you can't control them anymore. But you love them anyway.