Jump to content

Using the {enter} key as a Tab


ale1981
 Share

Go to solution Solved by Melba23,

Recommended Posts

  • 1 year later...

I have this question which I do not understand how to fix.  I want the Button3 to be available for Tab & Enter AND to be clicked on... One simply does not know what the user will do.

The only option I see is to define this BOTH inside the accelerator loop, and outside.  Options 1 and 2.  The ideal would be have it in one Case where regardless of keyboard/mouse click the action fires. 

I have modified the example above to show what I mean.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPI.au3>

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

Local $in1, $in2, $in3

$cInput_1 = GUICtrlCreateInput("", 10, 10, 200, 20)
            GUICtrlSetState($cInput_1, $GUI_FOCUS)
$cInput_2 = GUICtrlCreateInput("", 10, 50, 200, 20)
$cInput_3 = GUICtrlCreateInput("", 10, 90, 200, 20)

;$cButton_1 = GUICtrlCreateButton("Button 1", 250, 10, 80, 30)
;$cButton_2 = GUICtrlCreateButton("Button 2", 250, 50, 80, 30)
$cButton_3 = GUICtrlCreateButton("&Button 3", 250, 90, 80, 30)
            GUICtrlSetState($cButton_3, $GUI_DISABLE)

$cEnter = GUICtrlCreateDummy()

GUISetState()

Local $aAccelKeys[2][2] = [["{ENTER}", $cEnter], ["{TAB}", $cEnter]] ; Make {TAB} an accelerator
GUISetAccelerators($aAccelKeys)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
            ;#CS
            ;-- option one starts here
                Case $cButton_3 ; problem is that I want to able to click on this button!
                        $in1 = GUICtrlRead($cInput_1)
                        $in2 = GUICtrlRead($cInput_2)
                        $in3 = GUICtrlRead($cInput_3)
                        ConsoleWrite("Inputs display " & $in1 & " & " &  $in2 & " & "  & $in3 & @CRLF)
                        MsgBox(0,"It works!","If it works you will see this box" & @CRLF & _
                        "Inputs display " & $in1 & " & " &  $in2 & " & "  & $in3 & @CRLF,5)
                        ; return focus to $cInput_1
                        GUICtrlSetState($cInput_1, $GUI_FOCUS)
                        GUICtrlSetState($cButton_3, $GUI_DISABLE)
            ;-- option one end here
            ;#CE

        Case $cEnter
            Switch  _WinAPI_GetFocus()
                Case GUICtrlGetHandle($cInput_1)
                    ; Correct so move to next input
                        GUICtrlSetState($cInput_2, $GUI_FOCUS)
                    ; Not correct so stay in current input
                Case GUICtrlGetHandle($cInput_2)
                        GUICtrlSetState($cInput_3, $GUI_FOCUS)
                Case GUICtrlGetHandle($cInput_3)
                         GUICtrlSetState($cButton_3, $GUI_ENABLE)
                         GUICtrlSetState($cButton_3, $GUI_FOCUS)
                        ConsoleWrite("End" & @CRLF)
            #cs
            ;-- option two starts here

                Case GUICtrlGetHandle($cButton_3) ; problem is that I want to able to click on this button!
                        $in1 = GUICtrlRead($cInput_1)
                        $in2 = GUICtrlRead($cInput_2)
                        $in3 = GUICtrlRead($cInput_3)
                        ConsoleWrite("Inputs display " & $in1 & " & " &  $in2 & " & "  & $in3 & @CRLF)
                        MsgBox(0,"It works!","If it works you will see this box" & @CRLF & _
                        "Inputs display " & $in1 & " & " &  $in2 & " & "  & $in3 & @CRLF,5)
                        ; return focus to $cInput_1
                        GUICtrlSetState($cInput_1, $GUI_FOCUS)
                        GUICtrlSetState($cButton_3, $GUI_DISABLE)
            ;-- option two starts here
            #CE
                Case Else
                    GUISetAccelerators(0)                     ; Remove accelerator link
                    ControlSend($hGUI, "", "", "{TAB}")       ; Send {TAB} to the GUI
                    GUISetAccelerators($aAccelKeys)           ; Reset the accelerator

            EndSwitch
    EndSwitch

WEnd

 

Skysnake

Why is the snake in the sky?

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...