Jump to content

Tab switching with CTRL+TAB / CTRL+SHIFT+TAB


Go to solution Solved by Melba23,

Recommended Posts

Posted

In one program I seen functionality , in which the use of a combination of keys
CTRL + TAB or CTRL + SHIFT + TAB

results in a
switching tabs to the right or left.

Does anyone have an idea how to do it in AutoIt ?

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
  • Solution
Posted

mLipok,

If you want this functionality in an AutoIt GUI then I would use accelerator keys like this: :)

#include <GUIConstantsEx.au3>

Global $aTab[3]

$hGUI = GUICreate("Test", 500, 500)

$cTab = GUICtrlCreateTab(10, 10, 480, 200)

$aTab[0] = GUICtrlCreateTabItem("Tab 0")
$aTab[1] = GUICtrlCreateTabItem("Tab 1")
$aTab[2] = GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("")

$cTab_Right = GUICtrlCreateDummy()
$cTab_Left = GUICtrlCreateDummy()

GUISetState()

Global $aAccelKeys[2][2] = [["^{TAB}", $cTab_Right],["^+{TAB}", $cTab_Left]]
GUISetAccelerators($aAccelKeys)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cTab_Right
            $iTab = GUICtrlRead($cTab) + 1
            If $iTab > (UBound($aTab) - 1) Then $iTab = 0
            GUICtrlSetState($aTab[$iTab], $GUI_SHOW)
        Case $cTab_Left
            $iTab = GUICtrlRead($cTab) - 1
            If $iTab < 0 Then $iTab = UBound($aTab) - 1
            GUICtrlSetState($aTab[$iTab], $GUI_SHOW)
    EndSwitch
WEnd
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Melba23, you beat me to it, but I will post what I wrote anyways. Yours looks more efficient, though.

#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>

HotKeySet("^{TAB}", "_TabRight")
HotKeySet("^+{TAB}", "_TabLeft")

$Form1 = GUICreate("Form1", 444, 232)
$hWnd = GUICtrlCreateTab(16, 16, 409, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
GUICtrlSetState(-1, $GUI_SHOW)
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
$TabSheet4 = GUICtrlCreateTabItem("TabSheet4")
$TabSheet5 = GUICtrlCreateTabItem("TabSheet5")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _TabRight()
    $CurPos = _GUICtrlTab_GetCurSel($hWnd)
    _GUICtrlTab_SetCurSel($hWnd, $CurPos + 1)
EndFunc

Func _TabLeft()
    $CurPos = _GUICtrlTab_GetCurSel($hWnd)
    _GUICtrlTab_SetCurSel($hWnd, $CurPos - 1)
EndFunc
  • Moderators
Posted

aberration,

The only real difference is your use of HotKeys. I usually prefer Accelerators when dealing with GUIs as they are only active when the GUI is active and so do not interfere with other apps. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Thank you.
It works great.
By the way, enlightened me as to how to use GUICtrlCreateDummy(), and as to how to make this feature helpful.

As previously did not use it at all.

Cheers

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

mLipok,

Dummy controls can be very handy - see >here for some other suggested uses. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

This is inspirational.

Thanks.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

aberration,

I have added some explanatory remarks to the Help file page explaining the difference. ;)

mLipok,

Nice to hear. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 6/7/2014 at 3:35 PM, Melba23 said:

I have added some explanatory remarks to the Help file page explaining the difference. ;)

 

Very nice

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...