Jump to content

Trigger a function when pressing Enter on a GUI-Input


Recommended Posts

Hey all,

i have a GUI with inputs, and the purpose of those inputs is adding elements it works now by putting information in to the fields "GUICtrlCreateInput" fields and you can add them by using a add button "GUICtrlCreateButton" however its not that handy you keep mousing or tabbing to the add button and then shift tabbing back to the input field.

is it possible to run the function that should be triggered by the button by enter if its in a input field?

I thougth of using hotkeyset but that influences the whole envoinrent.

is there a better solution??

thanks

Matthy

Link to comment
Share on other sites

Hey all,

i have a GUI with inputs, and the purpose of those inputs is adding elements it works now by putting information in to the fields "GUICtrlCreateInput" fields and you can add them by using a add button "GUICtrlCreateButton" however its not that handy you keep mousing or tabbing to the add button and then shift tabbing back to the input field.

is it possible to run the function that should be triggered by the button by enter if its in a input field?

I thougth of using hotkeyset but that influences the whole envoinrent.

is there a better solution??

thanks

Matthy

$BS_DEFPUSHBUTTON use this style when creating the button also make sure to #include <ButtonConstants.au3>

this will make the button press when u hit enter

edit: lol beat mel to this one so they get all complex and out do my answer =(

Edited by norax
Link to comment
Share on other sites

  • Moderators

Matthy,

You mean like this: :mellow:

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

$gui = GUICreate( "test", 200, 200)
$inp = GUICtrlCreateInput("", 10, 10,100,20)
$but = GUICtrlCreateButton("clear text", 120, 10)
$hDummy = GUICtrlCreateDummy()
GUICtrlSetState($but, $GUI_HIDE)
GUISetState(@SW_SHOW)

; Set accelerator for Enter to action the Dummy code
Dim $AccelKeys[1][2]=[["{ENTER}", $hDummy]]
GUISetAccelerators($AccelKeys)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $hDummy
            ; Check input has focus
            If _WinAPI_GetFocus() = GUICtrlGetHandle($inp) Then
                $sText = GUICtrlRead($inp)
                MsgBox(0,"test", "You typed in " & $sText)
                GUICtrlSetState($but, $GUI_SHOW)
            EndIf
        Case $msg = $but
            GUICtrlSetData($inp, "")
            GUICtrlSetState($but, $GUI_HIDE)
    EndSelect

WEnd
GUIDelete()

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