Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Switching tabs programmatically?


  • Please log in to reply
3 replies to this topic
badmojo
  • Members
  • 204 posts
  • Last active: Jul 23 2014 01:39 AM
  • Joined: 11 Nov 2005
i would like the F2 key to switch tabs in a program. also if the last tab is active, it should revert to the 1st tab or move in reverse. how is this possible? i provide the code below..

#IfWinActive ahk_class #32770
F2::
SendMessage, 0x1304,,, SysTabControl321, ahk_class #32770  ; get total tabs
TabCount = %ErrorLevel%
ControlGet, WhichTab, Tab, , SysTabControl321	; get current tab

If WhichTab = TabCount				; if current tab equals total tab
  Control, TabLeft, , SysTabControl321		; move left
Else
  Control, TabRight, , SysTabControl321		; move right

;TrayTip, %appname%, TabCount = %TabCount%`nWhichTab = %WhichTab%
#IfWinActive


tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
I tried with the SendMessage example from the help file:
#IfWinActive,AutoHotkey Help
F2::
SendMessage, 0x1304,,, SysTabControl321, [color=red]A[/color]  ; get total tabs
TabCount = %ErrorLevel%
ControlGet, WhichTab, Tab, , SysTabControl321, [color=red]A[/color]   ; get current tab

If [color=red]WhichTab = %TabCount%[/color]            ; if current tab equals total tab
  SendMessage, 0x1330, 0,, SysTabControl321, [color=red]A[/color]
Else
  SendMessage, 0x1330, %WhichTab%,, SysTabControl321, [color=red]A[/color]
TrayTip, %appname%, TabCount = %TabCount%`nWhichTab = %WhichTab%
return
#IfWinActive
I tested with the help file for AHK, changes in red.

badmojo
  • Members
  • 204 posts
  • Last active: Jul 23 2014 01:39 AM
  • Joined: 11 Nov 2005
thanks tonne, it works! but being a dummy, can i know why it works? :)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
The ", A" part is actually not necessary since #IfWinActive sets the Last Found Window.

To know why
If WhichTab = %TabCount%
works where
If WhichTab = TabCount
does not, read FAQ: When exactly are variable names enclosed in percent signs?.