Unable to create/change global variable from within function
Posted: 10 Jan 2023, 04:38
While I've been making pretty good progress learning AHK2 as a beginner, I have become stumped on what should be an easy solution:
The purpose of my code is to capture the ahk_id of the current window when ^` are pressed, and assign the ahk_id to a global variable, window_id, so that the id can be accessed outside of the function (I plan to use the captured ahk_id with ControlSend).
My code
I have tried declaring my "global window_id" outside of the script but it is not behaving the way I want it to. Any feedback would be appreciated.
The purpose of my code is to capture the ahk_id of the current window when ^` are pressed, and assign the ahk_id to a global variable, window_id, so that the id can be accessed outside of the function (I plan to use the captured ahk_id with ControlSend).
My code
Code: Select all
^`:: {
global window_id
window_id := WinGetID("A")
MsgBox "All future uses of ControlSend will now act upon this window."
}
MsgBox window_id ; Throws the following error: "Error: This variable has not been assigned a value." Obviously, it is not able to access the variable.