Code to organise windows in a certain way

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wantToGo
Posts: 2
Joined: 16 Jan 2022, 15:11

Code to organise windows in a certain way

Post by wantToGo » 16 Jan 2022, 15:16

Code: Select all

;============================================================================;
;---+---               Appending running IDs to an array              ---+---;
;============================================================================;

Accounts := []

SetTitleMatchMode, 2
WinGet, Active, List,ahk_exe Notepad.exe 
Loop, %Active% {
    accountVar := Active%A_index%
    Accounts.Push(accountVar)
    ;MsgBox % Accounts[A_Index] ; This message box shows the IDs of each running client
}


;============================================================================;
;---+---                    Organising clients                        ---+---;
;============================================================================;

x = 3
y = 2
xcount := 0
ycount := 0
sw := A_ScreenWidth
sh := A_ScreenHeight

F2::
Loop, %Active% {
    xpos := (sw/x)*(xcount)
    ypos := (sh/y)*(ycount)
    accountX := Accounts[A_Index]
    MsgBox, %xcount%
         IF xcount = 3
        {
            ycount += 1
            MsgBox, ycount init %ycount%
            xcount := 1
            MsgBox, xcount init %xcount%
            ;MsgBox, %xpos% %ypos% iff
        } 
        WinMove,ahk_id %accountX%,, %xpos%, %ypos% 
            xcount += 1
            MsgBox, %xpos% %ypos%
       
}


Return

I'm trying to make a program which organises a given amount of windows into a nice format on my monitor. I know it may not look like it but I've been working on this for hours and I can't get it to work. I would really appreciate if someone could help me.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Code to organise windows in a certain way

Post by mikeyww » 16 Jan 2022, 15:37

It worked when I tested it, but I have no idea if "worked" means the same thing for you.

wantToGo
Posts: 2
Joined: 16 Jan 2022, 15:11

Re: Code to organise windows in a certain way

Post by wantToGo » 16 Jan 2022, 15:50

mikeyww wrote:
16 Jan 2022, 15:37
It worked when I tested it, but I have no idea if "worked" means the same thing for you.
Sorry I should have included the intended use. So say you open 6x of one application. Notepad in this example, although that is easily changed. It should sort the windows in a 3x2 configuration. So 3 across the top row and 3 across the bottom row. But mine won't sort in that order and I'm not sure why.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Code to organise windows in a certain way

Post by mikeyww » 16 Jan 2022, 16:05

Just before the WinMove, you can display the value of xpos and ypos. This seems likely to pinpoint the problem, which I think is that you updated xcount and ycount after xpos and ypos.

Code: Select all

F2::
SoundBeep, 1500
WinGet, Active, List, ahk_exe notepad.exe
Loop, %Active%
 WinMove, % "ahk_id " Active%A_Index%,
  , Mod(A_Index - 1, 3) * A_ScreenWidth / 3, (A_Index - 1) // 3 * A_ScreenHeight / 2
SoundBeep, 1000
Return

Post Reply

Return to “Ask for Help (v1)”