Blois Posted September 25, 2018 Posted September 25, 2018 Hi Guis, I need to create keyboard shortcut to navigate the tabs and activate them, but I could not use the code below: expandcollapse popup#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?
TheXman Posted September 25, 2018 Posted September 25, 2018 (edited) 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. expandcollapse popup#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 September 25, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Blois Posted September 25, 2018 Author Posted September 25, 2018 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.
TheXman Posted September 25, 2018 Posted September 25, 2018 I thought your issue was that it wasn't recognizing your hotkeys? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
TheXman Posted September 25, 2018 Posted September 25, 2018 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. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Blois Posted September 25, 2018 Author Posted September 25, 2018 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.
AutoBert Posted September 25, 2018 Posted September 25, 2018 (edited) 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 September 25, 2018 by AutoBert
TheXman Posted September 25, 2018 Posted September 25, 2018 (edited) Do you mean like this? Notice that I used _GUICtrlTab_ActivateTab() instead of GuiControlSetState() or GuiControlSetData(). expandcollapse popup#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 September 25, 2018 by TheXman Blois 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Blois Posted September 26, 2018 Author Posted September 26, 2018 15 hours ago, TheXman said: Do you mean like this? Notice that I used _GUICtrlTab_ActivateTab() instead of GuiControlSetState() or GuiControlSetData(). expandcollapse popup#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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now