Sign in to follow this  
Followers 0
scriptjunkie

How to get enter key, when in a field?

8 posts in this topic

Here is my example script:

#include <GUIConstants.au3>
#include <GUIComboBox.au3>
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 351, 59, 303, 219)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25)
$Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")
GUICtrlSetOnEvent($Button1, "_submitbtn")
GUICtrlSetOnEvent($Combo1, "_combobox")

While 1
    Sleep(1000)
WEnd

Func _quit()
    Exit
EndFunc

Func _submitbtn()
    $var = GUICtrlRead($Combo1)
    _GUICtrlComboBox_AddString($Combo1,$var)
EndFunc

Func _combobox()
    $var = GUICtrlRead($Combo1)
    msgbox(0,0,$var)
EndFunc

I tried searching the forum for how to get the event for when pressing enter. I could only find topics using a hotkey.

I'd like to have a way to type into the combo box, and press enter then run function _submitbtn().

Is this possible?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here is my example script:

#include <GUIConstants.au3>
#include <GUIComboBox.au3>
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 351, 59, 303, 219)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25)
$Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")
GUICtrlSetOnEvent($Button1, "_submitbtn")
GUICtrlSetOnEvent($Combo1, "_combobox")

While 1
    Sleep(1000)
WEnd

Func _quit()
    Exit
EndFunc

Func _submitbtn()
    $var = GUICtrlRead($Combo1)
    _GUICtrlComboBox_AddString($Combo1,$var)
EndFunc

Func _combobox()
    $var = GUICtrlRead($Combo1)
    msgbox(0,0,$var)
EndFunc

I tried searching the forum for how to get the event for when pressing enter. I could only find topics using a hotkey.

I'd like to have a way to type into the combo box, and press enter then run function _submitbtn().

Is this possible?

I don't understand very good. Like this?

#include <GUIConstants.au3>
#include <GUIComboBox.au3>
#include <Misc.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 351, 59, 303, 219)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25)
$Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

AdlibEnable("_submitbtn",100)
While 1
    $MSG = GUIGetMsg()
    Switch $MSG
        Case $Combo1
            Call("_combobox")
        Case $GUI_EVENT_CLOSE
            Call("_quit")
    EndSwitch
    Sleep(20)
WEnd

Func _quit()
    AdlibDisable()
    Exit
EndFunc

Func _submitbtn()
    If _IsPressed('0D') Then
    $var = GUICtrlRead($Combo1)
    _GUICtrlComboBox_AddString($Combo1,$var)
    EndIf
EndFunc

Func _combobox()
    $var = GUICtrlRead($Combo1)
    msgbox(0,0,$var)
EndFunc
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

search in the help for _IsPressed

Share this post


Link to post
Share on other sites

Or like this without Adlib.

#include <GUIConstants.au3>
#include <GUIComboBox.au3>
#include <Misc.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 351, 59, 303, 219)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25)
$Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0)
GUISetState(@SW_SHOW)
Global $LAST = ""
#EndRegion ### END Koda GUI section ###

$DLL = DllOpen('user32.dll')
While 1
    $MSG = GUIGetMsg()
    Switch $MSG
        Case $Combo1
            Call("_combobox")
        Case $GUI_EVENT_CLOSE
            Call("_quit")
    EndSwitch
    If _IsPressed('0D',$DLL) And $LAST <> GUICtrlRead($Combo1) Then
        Call("_submitbtn")
    EndIf
    Sleep(20)
WEnd

Func _quit()
    DllClose($DLL)
    Exit
EndFunc

Func _submitbtn()
    $LAST = GUICtrlRead($Combo1)
    _GUICtrlComboBox_AddString($Combo1,$LAST)
EndFunc

Func _combobox()
    $var = GUICtrlRead($Combo1)
    msgbox(0,0,$var)
EndFunc

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for the idea with ispressed. But, I have tried this. It doesn't work with sleep(1000) very well. If I hold down enter then it run the function multiple times.

ispressed, and hotkey the only options?

I guess I could do this with a shorter sleep time.

#include <GUIConstants.au3>
#include <GUIComboBox.au3>
#include <Misc.au3>
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 351, 59, 303, 219)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25)
$Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")
GUICtrlSetOnEvent($Button1, "_submitbtn")
GUICtrlSetOnEvent($Combo1, "_combobox")
$dll = DllOpen("user32.dll")

While 1
    Sleep(200)
    If _IsPressed("0D", $dll) Then _submitbtn()
WEnd

Func _quit()
    DllClose($dll)
    Exit
EndFunc

Func _submitbtn()
    $var = GUICtrlRead($Combo1)
    _GUICtrlComboBox_AddString($Combo1,$var)
EndFunc

Func _combobox()
    $var = GUICtrlRead($Combo1)
    msgbox(0,0,$var)
EndFunc
Edited by scriptjunkie

Share this post


Link to post
Share on other sites

Thanks for the idea with ispressed. But, I have tried this. It doesn't work with sleep(1000) very well. If I hold down enter then it run the function multiple times.

ispressed, and hotkey the only options?

I guess I could do this with a shorter sleep time.

#include <GUIConstants.au3>
#include <GUIComboBox.au3>
#include <Misc.au3>
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 351, 59, 303, 219)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25)
$Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")
GUICtrlSetOnEvent($Button1, "_submitbtn")
GUICtrlSetOnEvent($Combo1, "_combobox")
$dll = DllOpen("user32.dll")

While 1
    Sleep(200)
    If _IsPressed("0D", $dll) Then _submitbtn()
WEnd

Func _quit()
    DllClose($dll)
    Exit
EndFunc

Func _submitbtn()
    $var = GUICtrlRead($Combo1)
    _GUICtrlComboBox_AddString($Combo1,$var)
EndFunc

Func _combobox()
    $var = GUICtrlRead($Combo1)
    msgbox(0,0,$var)
EndFunc
Look example from post #4.

When the words fail... music speaks

Share this post


Link to post
Share on other sites

I believe it would fit better to use accelerators in this case.

#include <GUIConstantsEx.au3>;If you're using 3.2.10.0 or newer it's Ex that should be used.
#include <GUIComboBox.au3>
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 351, 59, 303, 219)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25)
$Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")
GUICtrlSetOnEvent($Button1, "_submitbtn")
GUICtrlSetOnEvent($Combo1, "_combobox")

Dim $AccelKeys[1][2]=[["{Enter}", $Button1]]
GUISetAccelerators($AccelKeys)

While 1
    Sleep(1000)
WEnd

Func _quit()
    Exit
EndFunc

Func _submitbtn()
    $var = GUICtrlRead($Combo1)
    _GUICtrlComboBox_AddString($Combo1,$var)
EndFunc

Func _combobox()
    $var = GUICtrlRead($Combo1)
    msgbox(0,0,$var)
EndFunc

Share this post


Link to post
Share on other sites

Thank you AdmiralAlkex. I did not know about this option because I was still on 3.2.10, but this worked perfectly.

=)

Share this post


Link to post
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
Sign in to follow this  
Followers 0