Code: Select all
Window := % "ahk_id" . WindowList%A_Index%
Code: Select all
Window := % "ahk_id" . WindowList%A_Index%
Code: Select all
#Requires AutoHotkey v1.1.33.11
Window1 := % "ahk_id"
Window2 := "ahk_id"
MsgBox % Window1 "`n" Window2
Code: Select all
#Requires AutoHotkey v2.0
For hWnd in WinGetList('ahk_exe notepad.exe')
WinActivate hWnd
Yeah, I'm using it in that context, trying to save msyelf from having to use it in every instance. Does this look right?In v2, ahk_id typically serves no critical role without multiple criteria in a WinTitle.
Code: Select all
MouseGetPos OutputVarX, OutputVarY, WinUMID, WinControl
MouseWindow := "ahk_id" . WinUMID
MouseWinClass := WinGetClass(MouseWindow)
Code: Select all
; example 1
animal_1 := 'hippo' ; animal is a hippo
animal_1 := ChangeAnimal1(animal_1) ; pass hippo to function and save value returned as the new animal
MsgBox(animal_1) ; displays giraffe
ChangeAnimal1(animal) {
return 'giraffe' ; return giraffe
}
; example 2
animal_2 := 'monkey' ; animal is a monkey
ChangeAnimal2(&animal_2) ; pass a reference of the animal to function that can be directly manipulated
MsgBox(animal_2) ; displays lion
ChangeAnimal2(&animal) {
animal := 'lion' ; change animal to lion
}
; example 3
animal_3 := 'snake' ; animal is a snake
ChangeAnimal3(animal_3) ; pass snake to function
MsgBox(animal_3) ; displays snake
ChangeAnimal3(animal) {
animal := 'mongoose' ; change local variable to mongoose (it is never used)
}
Code: Select all
MyFunc(&firstVar, &secondVar)
MsgBox(firstVar '`n' secondVar)
MyFunc(&var1?, &var2?) {
var1 := 'string one'
var2 := 'string two'
}
Code: Select all
Loop NumMonitors
{
MonNum := A_Index
OldMon%MonNum%WorkAreaRight := Mon%MonNum%WorkAreaRight
OldMon%MonNum%WorkAreaBottom := Mon%MonNum%WorkAreaBottom
Mon%MonNum% := MonitorGet(%MonNum%, &Mon%MonNum%Left, &Mon%MonNum%Top, &Mon%MonNum%Right, &Mon%MonNum%Bottom)
Mon%MonNum%WorkArea := MonitorGetWorkArea(%MonNum%, &Mon%MonNum%WorkAreaLeft, &Mon%MonNum%WorkAreaTop, &Mon%MonNum%WorkAreaRight, &Mon%MonNum%WorkAreaBottom)
}
Code: Select all
Mon%MonNum%Col%ColNumber% := Object()
Mon%MonNum%Col%ColNumber%["X"] := (((ColNumber - 1) * Mon%MonNum%ColWidth) + Mon%MonNum%Left)
Mon%MonNum%Col%ColNumber%["XEnd"] := ((((ColNumber - 1) * Mon%MonNum%ColWidth) + Mon%MonNum%ColWidth) + Mon%MonNum%Left)
Code: Select all
AddWindowTypes()
{
ObjRelease(WindowsToHack)
WindowsToHack := Object()
NumberOfItems := 0
WindowTypes := IniRead("WindowHacks.ini", "WindowTypes")
Loop Parse, WindowTypes, "`n"
{
PreferenceX := IniRead("WindowHacks.ini", A_LoopField, "PreferenceX")
If (PreferenceX)
{
NumberOfItems++
WindowsToHack.InsertAt(NumberOfItems, A_LoopField)
}
}
Loop Parse, WindowTypes, "`n"
{
PreferenceX := IniRead("WindowHacks.ini", A_LoopField, "PreferenceX")
If (!PreferenceX)
{
NumberOfItems++
WindowsToHack.InsertAt(NumberOfItems, A_LoopField)
}
}
; For Index, Element in WindowsToHack
; {
; MsgBox %Index%: %Element%
; }
}
Except I'm creating dynamic array names, resulting in something like this:boiler wrote: ↑14 Mar 2024, 01:08Use arrays instead. Use regular variables to get the values out of the MonitorGetWorkArea parameters, then assign them to your array elements. And even in v1, you wouldn’t put % around a variable in an expression like a function parameter as you have done with MonNum.
No, you don’t use Map for a simple array. And there is no reason for you to keep track of the number of items and use InsertAt for the next item. That’s what Push does.chinagreenelvis wrote: ↑ Apparently now Instead of Object(), I use Map() ? But I'm not able to use InsertAt on a map like I was on an Object. So I'm at a complete loss on how to convert this.
Code: Select all
AddWindowTypes()
{
WindowsToHack := []
WindowTypes := IniRead("WindowHacks.ini", "WindowTypes")
Loop Parse, WindowTypes, "`n"
{
PreferenceX := IniRead("WindowHacks.ini", A_LoopField, "PreferenceX")
If (PreferenceX)
WindowsToHack.Push(A_LoopField)
}
Loop Parse, WindowTypes, "`n"
{
PreferenceX := IniRead("WindowHacks.ini", A_LoopField, "PreferenceX")
If (!PreferenceX)
WindowsToHack.Push(A_LoopField)
}
; For Index, Element in WindowsToHack
; {
; MsgBox %Index%: %Element%
; }
}
Don't. Get out of the v1 dynamic variable name mindset. Use multi-dimensional arrays instead.chinagreenelvis wrote: ↑ Except I'm creating dynamic array names, resulting in something like this:
Mon1Col1[]
Mon1Col2[]
Mon2Col1[]
and so fourth, depending on how high MonNum and ColNum wind up being.
It was not the only way to do it. It was a way to do it. In v2, use arrays.chinagreenelvis wrote: ↑ The script works fine in v1 and embedding variables within variables using % signs was the only way to do it.
I hate to keep digging for help on this, but I really can't wrap my brain around any other way to do accomplish the following:
Code: Select all
Loop NumMonitors
{
MonNum := A_Index
OldMon%MonNum%WorkAreaRight := Mon%MonNum%WorkAreaRight
OldMon%MonNum%WorkAreaBottom := Mon%MonNum%WorkAreaBottom
Mon%MonNum% := MonitorGet(%MonNum%, &Mon%MonNum%Left, &Mon%MonNum%Top, &Mon%MonNum%Right, &Mon%MonNum%Bottom)
Mon%MonNum%WorkArea := MonitorGetWorkArea(%MonNum%, &Mon%MonNum%WorkAreaLeft, &Mon%MonNum%WorkAreaTop, &Mon%MonNum%WorkAreaRight, &Mon%MonNum%WorkAreaBottom)
}
MonNumPrimary := MonitorGetPrimary()
Loop NumMonitors
{
MonNum := A_Index
If (OldMon%MonNum%WorkAreaRight != Mon%MonNum%WorkAreaRight || OldMon%MonNum%WorkAreaBottom != Mon%MonNum%WorkAreaBottom)
{
GetGridInfo()
Break
}
}
GetGridInfo()
{
Global
Loop NumMonitors
{
MonNum := A_Index
ResX := (Mon%MonNum%Right - Mon%MonNum%Left)
ResY := (Mon%MonNum%Bottom - Mon%MonNum%Top)
Mon%MonNum%NumCols := IniRead("WindowHacks.ini", ResX . "x" . ResY, "NumCols")
Mon%MonNum%NumRows := IniRead("WindowHacks.ini", ResX . "x" . ResY, "NumRows")
Mon%MonNum%SpaceX := (Mon%MonNum%WorkAreaRight - Mon%MonNum%Left)
Mon%MonNum%SpaceY := (Mon%MonNum%WorkAreaBottom - Mon%MonNum%Top)
Mon%MonNum%ColWidth := (Mon%MonNum%SpaceX / Mon%MonNum%NumCols)
Loop Mon%MonNum%NumCols
{
ColNumber := A_Index
ObjRelease(Mon%MonNum%Col%ColNumber%)
Mon%MonNum%Col%ColNumber% := Object()
Mon%MonNum%Col%ColNumber%["X"] := (((ColNumber - 1) * Mon%MonNum%ColWidth) + Mon%MonNum%Left)
Mon%MonNum%Col%ColNumber%["XEnd"] := ((((ColNumber - 1) * Mon%MonNum%ColWidth) + Mon%MonNum%ColWidth) + Mon%MonNum%Left)
}
}
}
This was possible in v1.Note: A variable cannot be created by a dynamic reference, but existing variables can be assigned. This includes all variables which the script contains non-dynamic references to, even if they have not been assigned values.
Code: Select all
Loop 3
{
var%A_Index% := A_Index
}
Code: Select all
var := []
Loop 3 {
var.Push(A_Index)
}
Code: Select all
myMap := Map()
myMap["value1"] := "myValue"
myMap[1] := "number 1"
MsgBox myMap["value1"]
Code: Select all
obj := {}
obj.value1 := "myValue"
obj.1 := "number1"
MsgBox obj.1
MsgBox obj.%2-1% ; you can even evaluate expressions to access properties
Code: Select all
var%A_Index%also%Other_Index% := Object()
var%A_Index%also%Other_Index%["Key"] := someVariable
Code: Select all
var := [[Map("Key", "someVariable")]]
MsgBox var[1][1]["Key"]
Thanks, this might be what I'm looking for.Descolada wrote: ↑14 Mar 2024, 11:30@chinagreenelvis, you can nest objects as much as you want:Perhaps you could show a certain scenario which you want to convert to v2? There might be even better alternatives available.Code: Select all
var := [[Map("Key", "someVariable")]] MsgBox var[1][1]["Key"]
Code: Select all
Global Mon1Col1 := Map()
Mon%MonNum%Col%ColNumber%["X"] := WhateverVal
Code: Select all
MonCol := [[Map()]]
MonCol[MonNum][ColNumber]["X"] := WhateverVal
Code: Select all
Monitors := [] ; define the array of monitors
Monitors.Push([]) ; add array for columns
Monitors[1].Push({Width:0, Height:1}) ; column 1
Monitors[1].Push({Width:10, Height:10}) ; column 2
Monitors[1].Push({Width:100, Height:100}) ; column 3
MsgBox "There are " Monitors.length " monitors available"
MsgBox "Monitor 1 has " Monitors[1].Length " columns"
MsgBox "Monitor 1 column 1 width is " Monitors[1][1].Width
Users browsing this forum: Noitalommi_2 and 47 guests