Jump to content

Pressing ENTER in input control


Recommended Posts

Hi!

May be this was discussed many times... :mellow:

I'm trying to ENTER an input control.

In order to work I have to press BACKSPACE or LEFT/RIGHT ARROW first.

Here's the sample code:

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

Local $hGUI     = GUICreate("", 200, 100, -1, -1)
Local $hGUI_C   = GUICtrlCreateInput("X", 1, 1, 198, 21)

GUISetState(@SW_SHOW, $hGUI)

While 1
    Local $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $hGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $hGUI_C
                    _test()
            EndSwitch
    EndSwitch
WEnd

GUIDelete($hGUI)
Exit

Func _test()
    MsgBox(0, "", "", 0, GUICreate(""))
EndFunc

Please, could somebody help me?

Greets,

-supersonic.

Link to comment
Share on other sites

What do you want to achieve with your code?

The GUI now displays an input control with the content ("X") already selected. Why dow you want to press BACKSPACE or LEFT/RIGHT ARROW first?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

There are probably other easyer wayes that arnt so brutali like thisone (like focusing on defolt button on enter),

You can do it like this

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#Include <Misc.au3>

Local $hGUI     = GUICreate("test", 200, 100, -1, -1)
Local $hGUI_C   = GUICtrlCreateInput("Working ENTER", 1, 1, 198, 21)
Local $hGUI_D   = GUICtrlCreateInput("...", 1, 20, 198, 21)

GUISetState(@SW_SHOW, $hGUI)

While 1
    If _IsPressed("0D") And WinActive("test") And ControlGetFocus("test") = "Edit1" Then
        _test()
    EndIf
    Local $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $hGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $hGUI_C
            EndSwitch
    EndSwitch
WEnd

GUIDelete($hGUI)
Exit

Func _test()
    MsgBox(0, "", "", 0, GUICreate(""))
EndFunc
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

The input has the focus. I just want to press enter and - depending on the input data - an action starts...

Currently - in order to work - I first have to press BACKSPACE or LEFT/RIGHT ARROW within the input control.

Without, nothing happens...

I have changed the sample code:

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

Local $hGUI     = GUICreate("", 200, 100, -1, -1)
Local $hGUI_C   = GUICtrlCreateInput("", 1, 1, 198, 21)

GUISetState(@SW_SHOW, $hGUI)

While 1
    Local $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $hGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $hGUI_C
                    _test()
            EndSwitch
    EndSwitch
WEnd

GUIDelete($hGUI)
Exit

Func _test()
    Local $sTmp = GUICtrlRead($hGUI_C, 0)
    If Not $sTmp Then
        MsgBox(0, "", "Input control empty.")
    Else
        MsgBox(0, "", $sTmp)
    EndIf
EndFunc
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...