Jump to content

pressing ENTER into an InputBox


Recommended Posts

I just tried to search in the forum but wasn't able to find a solution to this simple problem.

I'd like to execute a function after the user has typed a value inyo an InpuBox and pressed ENTER.

At the moment I'm using a button that the user can press after having filled the inputbox, but I think that triggering the function right after the ENTER key is pressed should be better..

Anyone that already come up with this issue?

Thanks in advance!

Link to comment
Share on other sites

Have you looked at the function HotKeySet in the helpfile? You could probably do something like this (just a vague outline):

Yes I know HotKeySet, but I'd like to trigger my function only if ENTER is pressed while the cursor is inside the InputBox,

like it happens when I log in in this form and I press ENTER after typing my password..

Link to comment
Share on other sites

From help file:

Check out this button style:

$BS_DEFPUSHBUTTON

Description:

Creates a push button with a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely option, or default.

Link to comment
Share on other sites

No need to over-complicate things; an ENTER in an input box will register as a msg for the input control:

#include <GUIConstants.au3>

GUICreate(" My GUI input ", 320, 120)
$input = GUICtrlCreateInput("", 10, 5, 300, 20)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $input
            _myInput()
        Case Else
    EndSelect
WEnd

Func _myInput()
    MsgBox(0, "HI", "You pressed Enter in the input and so launched this function")
EndFunc
Link to comment
Share on other sites

@ ResNullius - That does not work right for me. If you type something into the first input, and then just click on the second to type something else in, it will trigger the event:

#include <GUIConstants.au3>

GUICreate(" My GUI input ", 320, 120)
$input = GUICtrlCreateInput("", 10, 5, 300, 20)
$input2 = GUICtrlCreateInput("", 10, 25, 300, 20)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $input
            _myInput()
        Case Else
    EndSelect
WEnd

Func _myInput()
    MsgBox(0, "HI", "You pressed Enter in the input and so launched this function")
EndFuncoÝ÷ Ø@ÈLȧyÚ²z-±ç¦¶(®Jâ^Ø^®+pYh°¢¹¢»ayø«²Ûb쨺޲ǧµêÚºÚ"µÍÚ[ÛYH ÑÕRPÛÛÝ[Ë]LÉÝÂÕRPÜX]J    ][ÝÈ^HÕRH[]  ][ÝËÌL
BÌÍÚ[]HÕRPÝÜX]R[]
    ][ÝÉ][ÝËL
KÌ
BÌÍÚ[]HÕRPÝÜX]R[]
    ][ÝÉ][ÝËLÍKÌ
BÌÍØ]ÛHÕRPÝÜX]P]Û   ][ÝÔÝXZ] ][ÝËL
KÌ ÌÍÐ×ÑQTÒUÓ
BÕRTÙ]Ý]J
BÌÍÛÙÈHÚ[H    ÌÍÛÙÈ  ÉÝÈ  ÌÍÑÕRWÑUSÐÓÔÑB ÌÍÛÙÈHÕRQÙ]ÙÊ
BÙ[XÝØÙH    ÌÍÛÙÈH ÌÍØ]ÛÛ^R[]

BØÙH[ÙB[Ù[XÝÑ[[ÈÛ^R[]

BÙÐÞ
    ][ÝÒI][ÝË   ][ÝÖ[ÝHÜÙY[Ú[HHÜ[]XYH    ][ÝÈ  [ÈÕRPÝXY
    ÌÍÚ[]
JB[[

So without complicating things a bit, we will have some wonky code.

Edited by danwilli
Link to comment
Share on other sites

  • 2 weeks later...

@ ResNullius - That does not work right for me. If you type something into the first input, and then just click on the second to type something else in, it will trigger the event:

...

So without complicating things a bit, we will have some wonky code.

A little late, but solved using Zedna's technique ( http://www.autoitscript.com/forum/index.ph...st&p=493696 )

with Dummy controls and the Accelerators in the latest Beta 3.2.11.5

;Requires AutoIt beta v 3.2.11.5
#include <GUIConstants.au3>

GUICreate(" My GUI input ", 320, 120)
$input = GUICtrlCreateInput("", 10, 5, 300, 20)
$input2 = GUICtrlCreateInput("", 10, 25, 300, 20)
$dummy = GUICtrlCreateDummy()
GUISetState()
Dim $aAccelerators[1][2] = [["{enter}", $Dummy]]
GUISetAccelerators($aAccelerators)
$msg = 0

While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $dummy
            _myInput()
        Case Else
    EndSelect
WEnd

Func _myInput()
    MsgBox(0, "HI", "You pressed Enter in the input and so launched this function")
EndFuncoÝ÷ Ù.q©ÚÊ/j¼­+,¢ØZ¶Ø^{^¯¥·¡j÷§¢¹z§v)à¢|!z·­çèrë"±«­¢+ØM±Ð(
ÍÀÌØíµÍôÀÌØíÕµµä(ÀÌØíÕÉÉ
ÑÉ°ô
½¹Ñɽ±Ñ½ÕÌ ÅÕ½Ðì5äU$¥¹ÁÕÐÅÕ½Ðì¤($$%MÝ¥Ñ ÀÌØíÕÉÉ
ÑÉ°($$$%
ÍÀÌØí¥¹ÁÕÐ=ÈÀÌØí¥¹ÁÕÐÈ($$$$%}µå%¹ÁÕÐ ¤($$$%
ͱÍ($$$$%M¹ ÅÕ½Ðíí9QIôÅÕ½Ðì¤($$%¹MÝ¥Ñ (
ͱÍ(¹M±
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...