langthang084 Posted December 25, 2015 Share Posted December 25, 2015 I want to Press Enter to Click Button on Gui1 and Gui 2, But It not work.Could any help me?Thanks all!expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GuiButton.au3> Global $hMain = GuiCreate("New AutoIt v3 Script", 228, 130, -1, -1) Global $Button_1 = GuiCtrlCreateButton("Button1", 60, 20, 140, 40) Global $Button_2 = GuiCtrlCreateButton("Button2", 60, 80, 140, 40) $Iddummy = GUICtrlCreateDummy() GUISetState() $Gui1 = GUICreate("GUI - 1", 200, 100, 0, 0) $ButtonGui1 = GUICtrlCreateButton("Test Gui1", 60, 20, 100, 40) GuiSetState(@SW_HIDE, $Gui1) $Gui2 = GUICreate("GUI - 2", 200, 100, 0, 0) $ButtonGui2 = GUICtrlCreateButton("Test Gui2", 60, 20, 100, 40) GuiSetState(@SW_HIDE, $Gui2) Local $aAccelKeys[1][2] = [["{enter}", $idDummy]] ;tạo hotkey (Ấn ENTER --> Tự động ấn ADD) GUISetAccelerators($aAccelKeys) Do Switch GuiGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 GUISetState(@SW_SHOWNORMAL, $Gui1) GuiSetState(@SW_HIDE, $Gui2) Case $Button_2 GUISetState(@SW_SHOWNORMAL, $Gui2) GuiSetState(@SW_HIDE, $Gui1) case $ButtonGui1 MsgBox(0, "", "Test GUI 1") case $ButtonGui2 MsgBox(0, "", "Test GUI 2") case $IdDummy _GUICtrlButton_Click($ButtonGui1) _GUICtrlButton_Click($ButtonGui2) ; EndSwitch Until False Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 25, 2015 Moderators Share Posted December 25, 2015 langthang084,Just reset the accelerator key each time you change the GUI:expandcollapse popup#include <GUIConstantsEx.au3> Global $hMain = GuiCreate("New AutoIt v3 Script", 228, 130, -1, -1) Global $Button_1 = GuiCtrlCreateButton("Button1", 60, 20, 140, 40) Global $Button_2 = GuiCtrlCreateButton("Button2", 60, 80, 140, 40) GUISetState() $Gui1 = GUICreate("GUI - 1", 200, 100, 0, 0) $ButtonGui1 = GUICtrlCreateButton("Test Gui1", 60, 20, 100, 40) GuiSetState(@SW_HIDE, $Gui1) $Gui2 = GUICreate("GUI - 2", 200, 100, 0, 0) $ButtonGui2 = GUICtrlCreateButton("Test Gui2", 60, 20, 100, 40) GuiSetState(@SW_HIDE, $Gui2) Do Switch GuiGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 GUISetState(@SW_SHOW, $Gui1) GuiSetState(@SW_HIDE, $Gui2) Local $aAccelKeys[1][2] = [["{enter}", $ButtonGui1]] GUISetAccelerators($aAccelKeys, $Gui1) Case $Button_2 GUISetState(@SW_SHOW, $Gui2) GuiSetState(@SW_HIDE, $Gui1) Local $aAccelKeys[1][2] = [["{enter}", $ButtonGui2]] GUISetAccelerators($aAccelKeys, $Gui2) case $ButtonGui1 MsgBox(0, "", "Test GUI 1") case $ButtonGui2 MsgBox(0, "", "Test GUI 2") EndSwitch Until FalseM23 langthang084 and Xandy 2 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
langthang084 Posted December 25, 2015 Author Share Posted December 25, 2015 Thanks Melba23!But if I have many Gui, Is there anyway to create the list accelerator keys like _GUICtrlButton_Click($ButtonGui1) with $IdDummy above? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 25, 2015 Moderators Share Posted December 25, 2015 langthang084,I think not - Accelerator keys are only active if the GUI with which they are associated is active, so as soon as one of the other GUIs has focus the dummy control will not fire.You could do something like this - store the GUI handles and associated ControlDs in an array:expandcollapse popup#include <GUIConstantsEx.au3> Global $hMain = GUICreate("New AutoIt v3 Script", 228, 130, -1, -1) Global $Button_1 = GUICtrlCreateButton("Button1", 60, 20, 140, 40) Global $Button_2 = GUICtrlCreateButton("Button2", 60, 80, 140, 40) GUISetState() $Gui1 = GUICreate("GUI - 1", 200, 100, 0, 0) $ButtonGui1 = GUICtrlCreateButton("Test Gui1", 60, 20, 100, 40) GUISetState(@SW_HIDE, $Gui1) $Gui2 = GUICreate("GUI - 2", 200, 100, 0, 0) $ButtonGui2 = GUICtrlCreateButton("Test Gui2", 60, 20, 100, 40) GUISetState(@SW_HIDE, $Gui2) ; Array holding GUI handles and controls Global $aGUIData[3][2] = [[0, 0], [$Gui1, $ButtonGui1], [$Gui2, $ButtonGui2]] Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 GUISetState(@SW_SHOW, $Gui1) GUISetState(@SW_HIDE, $Gui2) _SetAccel(1) Case $Button_2 GUISetState(@SW_SHOW, $Gui2) GUISetState(@SW_HIDE, $Gui1) _SetAccel(2) Case $ButtonGui1 MsgBox(0, "", "Test GUI 1") Case $ButtonGui2 MsgBox(0, "", "Test GUI 2") EndSwitch Until False Func _SetAccel($iIndex) ; Set accelerators for the active GUI Local $aAccelKeys[1][2] = [["{ENTER}", $aGUIData[$iIndex][1]]] GUISetAccelerators($aAccelKeys, $aGUIData[$iIndex][0]) EndFunc ;==>_SetAccelM23 langthang084 1 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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