Jump to content

press enter while in textbox or input


Go to solution Solved by Queener,

Recommended Posts

I'm kind of lost on how to code this; when the cursor focus in the input box or textbox and user press Enter, it calls a function.

Only guess that I can think of is:

 
While GUICtrlSetState($searchinput, $GUI_FOCUS)
if send("{ENTER}") then
testfunction()
endif
WEnd
Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

I'm not sure about the input box ect. but here's how you can detect when they press enter.

http://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm

IE:

#include <Misc.au3>

Local $hDLL = DllOpen("user32.dll")

While 1
    If _IsPressed("0D", $hDLL) Then
        MsgBox(0, "Test", "Enter was pressed")
    EndIf
    Sleep(250)
WEnd
Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

  • Moderators

You can do this with Accelerators. Something like this:

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

GUICreate("Test", 300, 300)
$input = GUICtrlCreateInput("", 10, 10, 280, 100)
Local $accelerators[1][2]
    $accelerators[0][0] = "{ENTER}"
    $accelerators[0][1] = $input

GUISetAccelerators($accelerators)

GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $input
                MsgBox(0, "", "Enter Sent")
        EndSwitch
    WEnd

GUIDelete()

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Without accelerators.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $Button_1, $Button_2, $msg
    GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("Run Notepad", 10, 30, 100, 20, $BS_DEFPUSHBUTTON) ;make default button
    $Button_2 = GUICtrlCreateButton("Button Test", 0, -1)
    GUICtrlCreateInput("", 10, -1, 200, 20); when ebter pressed with focus on input, acts like default button was pressed. and will in this case run notepad

    GUISetState() ; will display an  dialog box with 2 button

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                Run('notepad.exe') ; Will Run/Open Notepad
            Case $msg = $Button_2
                MsgBox(0, 'Testing', 'Button 2 was pressed') ; Will demonstrate Button 2 being pressed
        EndSelect
    WEnd
EndFunc   ;==>Example

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • 2 weeks later...
  • Solution

thanks for the info, but this works well for me. I got from searching the forum...

Local $nMsg[5]
While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[0]
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $ExitB1
            _Exit()
        Case $searchinput ;when press Enter, go to Func Search
            Search()
    EndSwitch
WEnd

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
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...