Hello!
I'm new to autohotkey.
My intention is to use it with the tracker Jeskola Buzz.
My first issue is toggling between two windows. I want them on the screen side by side. To be able to control them the window have to be active and I would like to activate them without fiddling with the mouse.
With the help of tutorials and manuals I have learnt how to create hotkeys to activate windows so I now have two hotkeys, one for each window. My question is: is there a way to toggle between the two windows using only one hotkey? I mean, in a similar way that alt+tab can be used to toggle between active programs on the computer, could this be done inside a program?
[SOLVED] Can I toggle between two windows with one shortcut?
-
- Posts: 3
- Joined: 24 Oct 2015, 17:44
[SOLVED] Can I toggle between two windows with one shortcut?
Last edited by andersbrontosaurus on 26 Oct 2015, 17:27, edited 2 times in total.
Re: Can I toggle betwwen two windows with one shortcut?
This should get you started:
Code: Select all
F1::
QuickToggle:=!QuickToggle
If (QuickToggle)
WinActivate App1
Else
WinActivate App2
Return
Re: Can I toggle betwwen two windows with one shortcut?
Nextron's script falls short if you manually activate one of the windows - i.e. you might need to press the hotkey twice to have an effect.
Another way is to check which window is active:App1 and App2 are window titles, as in Nextron's script. You can extend this to work with as many windows as you want by simply adding one else if..WinActivate for each window.
But actually, there's a built-in command for this: GroupActivate.Once again, App1 and App2 are window titles. Swap is just a name I chose. Because the hotkey only calls one command, we can write it on one line and omit return. GroupAdd should be placed in the auto-execute section. (It can be called from anywhere, but if you put it below a hotkey it probably won't be called at all.)
Another way is to check which window is active:
Code: Select all
F1::
if !WinActive("App1")
WinActivate App1
else if !WinActive("App2")
WinActivate App2
return
But actually, there's a built-in command for this: GroupActivate.
Code: Select all
GroupAdd Swap, App1
GroupAdd Swap, App2
; Add as many window titles to the group as you want.
F1::GroupActivate Swap
-
- Posts: 3
- Joined: 24 Oct 2015, 17:44
Re: Can I toggle between two windows with one shortcut?
@Nextron @lexikos thanks a lot for your input! This will keep my brain occupied today.
Lexikos, the way I as a novice understand your first script it activates the already active window. Maybe it has something to do with the "!" in the beginning of !ifwinactive. I need to learn what those prefixes do...
...but groupactivate seems perfect for what I need.
Lexikos, the way I as a novice understand your first script it activates the already active window. Maybe it has something to do with the "!" in the beginning of !ifwinactive. I need to learn what those prefixes do...
...but groupactivate seems perfect for what I need.
Re: Can I toggle between two windows with one shortcut?
The ! basically means 'not'. It interprets the next value as binary and returns the opposite value. So in this case, if app1 is not active, activate it. Although I'm not seeing the extensibility to a third window in either my or Lexikos' example; another if else would only execute if all former windows are simultaneously active.
I did not know about the GroupActivate, I'd stick with that one too.
I did not know about the GroupActivate, I'd stick with that one too.
Re: Can I toggle between two windows with one shortcut?
You're right, that was silly of me.... another if else would only execute if all former windows are simultaneously active.
-
- Posts: 3
- Joined: 24 Oct 2015, 17:44
Re: Can I toggle between two windows with one shortcut?
Sweet as!
Groupaddon works perfect for my need.
Thanks a lot!
Groupaddon works perfect for my need.
Thanks a lot!
Who is online
Users browsing this forum: Bing [Bot], digdugdirk, doubledave22, TAC109, timebones and 60 guests