Jump to content

GUISetAccelerators with Multi GUI?


langthang084
 Share

Recommended Posts

I want to Press Enter to Click Button on Gui1 and Gui 2, But It not work.

Could any help me?

Thanks all!

#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

  • Moderators

langthang084,

Just reset the accelerator key each time you change the GUI:

#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 False

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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:

#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   ;==>_SetAccel

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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