Jump to content
Blois

HOTKEYS TAB GUI

Recommended Posts

Hi Guis,

 

I need to create keyboard shortcut to navigate the tabs and activate them, but I could not use the code below:

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


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


$gui = GUICreate("test",450, 300)

$Tab1 = GUICtrlCreateTab(20, 24, 425, 201)
$TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1")
$lbContagemGrupos2 = GUICtrlCreateLabel("aaaa", 50, 50)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateTabItem("")
$TabSheet2 = GUICtrlCreateTabItem(" ")
$TabSheet3 = GUICtrlCreateTabItem(" ")

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _TabRight()
    $CurPos = _GUICtrlTab_GetCurSel($Tab1)
    _GUICtrlTab_SetCurSel($Tab1, $CurPos + 1)
    $tab = "$TabSheet" & $CurPos
    GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW)
    Return
EndFunc

Func _TabLeft()
    $CurPos = _GUICtrlTab_GetCurSel($Tab1)
    _GUICtrlTab_SetCurSel($Tab1, $CurPos - 1)
    $tab = "$TabSheet" & $CurPos
    GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW)
    Return
EndFunc


Exit

 

can you help me?

Share this post


Link to post
Share on other sites

Try this.  It uses GUISetAccelerators instead of hotkey.  This is probably better since you are trying to override default Windows hotkeys.  GUISetAccelerators will only do it while your GUI is active.  Of course you should probably add additional logic to make sure that you are not trying to set the tab index less than the first or greater than the last tab.  Also, you didn't need the GUISetState functions in the _TabLeft and _TabRight functions.

For the record, your original logic would have worked by just taking out the GUISetState functions in your _TabRight() and _TabLeft() functions.  However, as stated above, you only want to use those accelerators while your GUI is active, not system-wide.

 

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


;~ HotKeySet("^{tab}\r", "_TabRight")
;~ HotKeySet("^+{tab}", "_TabLeft")


$gui = GUICreate("test",450, 300)

$PrevTab   = GUICtrlCreateDummy()
$NextTab   = GUICtrlCreateDummy()

$Tab1 = GUICtrlCreateTab(20, 24, 425, 201)
$TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1")
$lbContagemGrupos2 = GUICtrlCreateLabel("aaaa", 50, 50)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateTabItem("")
$TabSheet2 = GUICtrlCreateTabItem(" ")
$TabSheet3 = GUICtrlCreateTabItem(" ")

Global $aAccels[2][2] = [["^+{tab}", $PrevTab], ["^{tab}", $NextTab]]
GUISetAccelerators($aAccels)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $PrevTab
            _TabLeft()
        Case $NextTab
            _TabRight()
    EndSwitch
WEnd

Func _TabRight()
    ConsoleWrite("Right" & @CRLF)
    $CurPos = _GUICtrlTab_GetCurSel($Tab1)
    _GUICtrlTab_SetCurSel($Tab1, $CurPos + 1)
    $tab = "$TabSheet" & $CurPos
;~     GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW)
    Return
EndFunc

Func _TabLeft()
    ConsoleWrite("Left" & @CRLF)
    $CurPos = _GUICtrlTab_GetCurSel($Tab1)
    _GUICtrlTab_SetCurSel($Tab1, $CurPos - 1)
    $tab = "$TabSheet" & $CurPos
;~     GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW)
    Return
EndFunc


Exit

 

Edited by TheXman

Share this post


Link to post
Share on other sites
1 hour ago, TheXman said:

Try this.  It uses GUISetAccelerators instead of hotkey.  This is probably better since you are trying to override the default windows hotkey.  This will only do it while your GUI is active.  Of course you should add additional logic to make sure you are not trying to set the tab index higher or lower than the actual number of tabs.  Also, you didn't need the additional GUISetState in the _left and _right functions.

For the record, your original logic would have worked by just taking out the GUISetState functions in your _TabRight() and _TabLeft() functions.  However, as stated above, you only want to use those accelerators while your GUI is active, not system-wide.

 

 

 

Label aaaa is in TAB1, but when using the shortcuts it is still shown in TAB2.
I validated that it is not enabling the TAB and just walking through them.

image.png.17ab97ebe9d4d4366fb877f322dcaa39.png

 

Share this post


Link to post
Share on other sites

I'm not being critical, just factual.  I looked at your code, and other than changing tabs using a hotkey, I don't have a clue what you're trying to do.

So maybe you can start with a detailed explanation of what it is you are trying to accomplish, what results you are expecting, and any other information that may be be relevant to someone trying to help you help yourself.

Share this post


Link to post
Share on other sites

I'm sorry, my English is bad.

In the code that you helped me I can walk the TABS, but only the TABS are changed, the contents always remain the one of TAB1.

Example:
In TAB1 there is a label with the caption "aaaaa", when it changes to TAB2 the contents of TAB1 appear, so it has not changed to the contents of TAB2.

It looks like it does not activate the next TAB just browsing between them.

Share this post


Link to post
Share on other sites

Your problem is by creating the GUI, corected:

$PrevTab   = GUICtrlCreateDummy()
$NextTab   = GUICtrlCreateDummy()

$Tab1 = GUICtrlCreateTab(20, 24, 425, 201)
$TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1")
$lbContagemGrupos2 = GUICtrlCreateLabel("aaaa", 50, 50)
GUICtrlSetColor(-1, 0x0000FF)
$TabSheet2 = GUICtrlCreateTabItem(" ")
$TabSheet3 = GUICtrlCreateTabItem(" ")
GUICtrlCreateTabItem("")

GUISetState()

GUICtrlCreateTabItem("") must be after last tabsheet is created.

Edited by AutoBert

Share this post


Link to post
Share on other sites

Do you mean like this?  Notice that I used _GUICtrlTab_ActivateTab() instead of GuiControlSetState() or GuiControlSetData().

 

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


;~ HotKeySet("^{tab}\r", "_TabRight")
;~ HotKeySet("^+{tab}", "_TabLeft")


$gui = GUICreate("test",450, 300)

$PrevTab   = GUICtrlCreateDummy()
$NextTab   = GUICtrlCreateDummy()

$Tab1 = GUICtrlCreateTab(20, 24, 425, 201)
$TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1")
$lb1 = GUICtrlCreateLabel("aaaa", 50, 50)
$TabSheet2 = GUICtrlCreateTabItem("Tabsheet 2")
$lb2 = GUICtrlCreateLabel("bbbb", 50, 50)
$TabSheet3 = GUICtrlCreateTabItem("Tabsheet 3")
$lb3 = GUICtrlCreateLabel("cccc", 50, 50)
GUICtrlCreateTabItem("")

Global $aAccels[2][2] = [["^+{tab}", $PrevTab], ["^{tab}", $NextTab]]
GUISetAccelerators($aAccels)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $PrevTab
            _TabLeft()
        Case $NextTab
            _TabRight()
    EndSwitch
WEnd

Func _TabRight()
    $CurPos = _GUICtrlTab_GetCurSel($Tab1)
    If $CurPos < _GUICtrlTab_GetItemCount($Tab1) - 1 Then
        _GUICtrlTab_ActivateTab($Tab1, $CurPos + 1)
        ConsoleWrite("Tab Right" & @CRLF)
    EndIf
EndFunc

Func _TabLeft()
    $CurPos = _GUICtrlTab_GetCurSel($Tab1)
    If $CurPos > 0 Then
        _GUICtrlTab_ActivateTab($Tab1, $CurPos - 1)
        ConsoleWrite("Tab Left" & @CRLF)
    EndIf
EndFunc

 

Edited by TheXman

Share this post


Link to post
Share on other sites
15 hours ago, TheXman said:

Do you mean like this?  Notice that I used _GUICtrlTab_ActivateTab() instead of GuiControlSetState() or GuiControlSetData().

 

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


;~ HotKeySet("^{tab}\r", "_TabRight")
;~ HotKeySet("^+{tab}", "_TabLeft")


$gui = GUICreate("test",450, 300)

$PrevTab   = GUICtrlCreateDummy()
$NextTab   = GUICtrlCreateDummy()

$Tab1 = GUICtrlCreateTab(20, 24, 425, 201)
$TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1")
$lb1 = GUICtrlCreateLabel("aaaa", 50, 50)
$TabSheet2 = GUICtrlCreateTabItem("Tabsheet 2")
$lb2 = GUICtrlCreateLabel("bbbb", 50, 50)
$TabSheet3 = GUICtrlCreateTabItem("Tabsheet 3")
$lb3 = GUICtrlCreateLabel("cccc", 50, 50)
GUICtrlCreateTabItem("")

Global $aAccels[2][2] = [["^+{tab}", $PrevTab], ["^{tab}", $NextTab]]
GUISetAccelerators($aAccels)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $PrevTab
            _TabLeft()
        Case $NextTab
            _TabRight()
    EndSwitch
WEnd

Func _TabRight()
    $CurPos = _GUICtrlTab_GetCurSel($Tab1)
    If $CurPos < _GUICtrlTab_GetItemCount($Tab1) - 1 Then
        _GUICtrlTab_ActivateTab($Tab1, $CurPos + 1)
        ConsoleWrite("Tab Right" & @CRLF)
    EndIf
EndFunc

Func _TabLeft()
    $CurPos = _GUICtrlTab_GetCurSel($Tab1)
    If $CurPos > 0 Then
        _GUICtrlTab_ActivateTab($Tab1, $CurPos - 1)
        ConsoleWrite("Tab Left" & @CRLF)
    EndIf
EndFunc

 

Tks!

 

Good Work.

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • By matwachich
      Hi AutoIters!
      Here is my new UDF about GUIs: it's an enhanced mixture of Advanced InputBox (deprecated) and KODA Parser (deprecated), with additional functions.
      What you can do with it:
      Parse KODA files and directly create GUIs (_GUIUtils_CreateFromKODA) Parse a simple JSON form definition to simply create advanced InputBoxes with any amount/type of input controls (_GUIUtils_CreateFromJSON) Created GUIs are returned as Scripting.Dictionary objects, and you have helper functions to access GUIs controls by their names (_GUIUtils_HWnd, _GUIUtils_CtrlID, _GUIUtils_HCtrl ...) A function that can make a GUI created from KODA/JSON (defined by it's $oForm object) and make it a modal InputDialogBox (just like InputBox, but returns all entered data as Scripting.Dictionary object) Functions are documented, and there are some examples.
      Consider this UDF as beta, but since I'm currently using it in a small commercial project, it should become production ready in near future.
      To always get the latest code version, get it from Github (more up to date than this topic).
      Update 04/02/2020:
      New simple application example Fixed focused control handling in _GUIUtils_InputDialog Reset input values before returning from _GUIUtils_InputDialog Fixed CloseOnEsc in _GUIUtils_InputDialog Fixed Input not reset Fixed all ListBox items are selected Project now on GitHub https://github.com/matwachich/autoit-guiutils/
      Update 05/02/2020:
      Support for nodate for Date and Time input controls (pass null value) New handling of focused control _GUIUtils_InputDialog: Now, you can specify the focused control in $oInitialData by setting "controlName:focus" = True Updated documentation of _GUIUtils_InputDialog Update 07/02/2020:
      Bug corrected when setting Data input control Added: abillity to read a single input control New functions (_GUIUtils_GetInputs, _GUIUtils_WriteInputs), documentation completion. Readme file and screenshots on Github Page  
      GUIUtils.zip
    • By antonioj84
      I am not able to use the $GUI_READ_EXTENDED with the  Metro UDF,  any work around ?
      Local $aPos[2] = [$Radio1, $Radio2] For $Radio In $aPos If GUICtrlRead($Radio) = $GUI_UNCHECKED Then ContinueLoop IniWrite($sGUIstate_IniFile, "Data", "POS", GUICtrlRead($Radio, $GUI_READ_EXTENDED)) ;; return the text of the menu item ExitLoop Next  
    • By _Vlad
      Hello forum,
      I want to create a program with multiple menus and many elements inside. The problem is my way of doing this and below I have an example of how I do these menus.
      I know it's a bad way of doing them as using this method for more elements and menus cause big flickering.
       
      Can someone please help me with some tips of optimizing this or tell me another way of creating that menus with many elements without cause flickering? From a long time ago I still try to solve this but without any results, just small improvements.
      Many thanks for everyone.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $MENU_HOVER = '' Global $MENU_SELECTED = '' Global $COLOR_STANDARD = 0x94A5E9 Global $COLOR_HOVER = 0x8292d1 Global $COLOR_SELECTED = 0x7584bf $MENU = GUICreate("Menu", 615, 437, -1, -1, -1, -1, 0) GUISetFont(10, 400, 0, "Arial") $MENU_1 = GUICtrlCreateLabel("Menu 1", 8, 24, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE)) $MENU_2 = GUICtrlCreateLabel("Menu 2", 8, 56, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE)) $MENU_3 = GUICtrlCreateLabel("Menu 3", 8, 88, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ;MENU 1 ELEMENTS $MENU_1_ELEMENT_1 = GUICtrlCreateButton("Menu1 Button", 128, 24, 147, 25) ;MENU 2 ELEMENTS $MENU_2_ELEMENT_1 = GUICtrlCreateButton("Menu2 Button", 128, 24, 147, 25) $MENU_2_ELEMENT_2 = GUICtrlCreateLabel("Another element", 128, 64, 99, 20) _Design() _Hide_All() GUISetState(@SW_SHOW, $MENU) While 1 $Cursor = GUIGetCursorInfo($MENU) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MENU_1 _Previous_Selected_Cancel() $MENU_SELECTED = 'Menu1' GUICtrlSetBkColor($MENU_1, $COLOR_SELECTED) _Show('Menu1') Case $MENU_2 _Previous_Selected_Cancel() $MENU_SELECTED = 'Menu2' GUICtrlSetBkColor($MENU_2, $COLOR_SELECTED) _Show('Menu2') Case $MENU_3 _Previous_Selected_Cancel() $MENU_SELECTED = 'Menu3' GUICtrlSetBkColor($MENU_3, $COLOR_SELECTED) _Show('Menu3') EndSwitch If $Cursor[4] = $MENU_1 Then If $MENU_HOVER <> 'Menu1' And $MENU_SELECTED <> 'Menu1' Then _Previous_Hover_Cancel() GUICtrlSetBkColor($MENU_1, $COLOR_HOVER) $MENU_HOVER = 'Menu1' EndIf ElseIf $Cursor[4] = $MENU_2 Then If $MENU_HOVER <> 'Menu2' And $MENU_SELECTED <> 'Menu2' Then _Previous_Hover_Cancel() GUICtrlSetBkColor($MENU_2, $COLOR_HOVER) $MENU_HOVER = 'Menu2' EndIf ElseIf $Cursor[4] = $MENU_3 Then If $MENU_HOVER <> 'Menu3' And $MENU_SELECTED <> 'Menu3' Then _Previous_Hover_Cancel() GUICtrlSetBkColor($MENU_3, $COLOR_HOVER) $MENU_HOVER = 'Menu3' EndIf Else _Previous_Hover_Cancel() $MENU_HOVER = 'Idle' EndIf WEnd Func _Design() GUICtrlSetColor($MENU_1, 0xFFFFFF) GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD) GUICtrlSetCursor($MENU_1, 0) GUICtrlSetColor($MENU_2, 0xFFFFFF) GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD) GUICtrlSetCursor($MENU_2, 0) GUICtrlSetColor($MENU_3, 0xFFFFFF) GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD) GUICtrlSetCursor($MENU_3, 0) EndFunc ;==>_Design Func _Hide_All() GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_HIDE) GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_HIDE) GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_HIDE) EndFunc ;==>_Hide_All Func _Show($MENU_SHOW) _Hide_All() If $MENU_SHOW = 'Menu1' Then GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_SHOW) ElseIf $MENU_SHOW = 'Menu2' Then GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_SHOW) GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_SHOW) ElseIf $MENU_SHOW = 'Menu3' Then EndIf EndFunc ;==>_Show Func _Previous_Hover_Cancel() If $MENU_HOVER = 'Menu1' Then If $MENU_SELECTED <> 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD) ElseIf $MENU_HOVER = 'Menu2' Then If $MENU_SELECTED <> 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD) ElseIf $MENU_HOVER = 'Menu3' Then If $MENU_SELECTED <> 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD) EndIf EndFunc ;==>_Previous_Hover_Cancel Func _Previous_Selected_Cancel() If $MENU_SELECTED = 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD) If $MENU_SELECTED = 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD) If $MENU_SELECTED = 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD) EndFunc ;==>_Previous_Selected_Cancel  
    • By Tony007
      Hi,
      is it possible to export only the area "$idOutput" with the TEXT as a PNG?
      Thanks
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Example() Func Example() Local $hGUI = GUICreate("Test", 700, 700, -1, -1) Local $input1 = GUICtrlCreateInput("", 10, 10, 150, 20) Local $idButtonStart = GUICtrlCreateButton("Start", 200, 10, 50, 30) Local $idButtonClear = GUICtrlCreateButton("Clear", 260, 10, 50, 30) Local $idButtonExport = GUICtrlCreateButton("Export", 320, 10, 50, 30) Local $idOutput = GUICtrlCreateLabel("TEXT", 10, 50, 500, 500, BitOR($BS_PUSHLIKE, $SS_CENTER)) GUICtrlSetFont($idOutput, 45, 800, "", "Impact") GUISetState(@SW_SHOW, $hGUI) ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButtonStart $ContentInput1 = GUICtrlRead($input1) GUICtrlSetData($idOutput, $ContentInput1) Case $idButtonClear GUICtrlSetData($input1, "") GUICtrlSetData($idOutput, "") Case $idButtonExport EndSwitch WEnd GUIDelete($hGUI) Exit EndFunc ;==>Example  
    • By muchki
      i am more or less happy with my code
      only the X button does not exit
      what can i do?
      I made an 'exit' button and it works
      pressing Esc works
      just the X button not working
       
      here's my code:
       
      URLTrimmer 1.5.2 12 21 2019.txt
×
×
  • Create New...