Hello!
It should be tons of scripts and code out there to fit the need for what you are trying to achieve
What you have found is a basic toggle script and are to find all over the Interwebz, including the old and the new site of AHK.
Many times, especially when new to a subjects like AHK, it can be hard to know what too look for, so here is a
link to a small repository of useful starter scripts that can be handy to learn and implement in to your scripts. It might not be exact what you are looking for in term of what your goal is, but it is a good start for sure.
It also include your findings for the toggle script.
Good luck!