Jump to content

how to disable enter key from within input box


coachjer
 Share

Recommended Posts

I am trying to either not allow the enter key to work after entering data in a input box OR have the data that is entered actually be captured when the enter key is used instead of the OK button.

If the user enters the data, then clicks ok, everything goes as planned, but if they use the enter key on the keyboard, the data from the input box is not captured.

I am really new to using AutoIT and this is my first script. Below is the coding I am using for this function

    ; Runs command prompt to get local network ipconfig, saves to file to be called later
    Local $local = Run(@ComSpec & " /k", "", @SW_HIDE, $STDIN_CHILD)
    StdinWrite($local, "ipconfig > ipconfig.txt") ; need to change to send file to temp directory so user does not see file created
    StdinWrite($local, @CRLF)
    ; Gives times time for ipconfig to be written
    Sleep(5000)
    Local $ipconfigread = FileRead("ipconfig.txt") ; carry over location change
    $dgate = InputBox("Please enter Default Gateway", $ipconfigread, "", "", 400, 850, -1, -1) ; If user presses enter key after entering address, the script does not grab the input value

    Local $pgate = Run(@ComSpec & " /k", "", @SW_HIDE, $STDIN_CHILD)
    ; ping test to local gateway with output to text file
    StdinWrite($pgate, "ping -n ")
    StdinWrite($pgate, ($amt))
    StdinWrite($pgate, ($dgate))
    StdinWrite($pgate, " >> LocalGatewayPing.txt")
    StdinWrite($pgate,@CRLF)
 

Link to comment
Share on other sites

Following works fine for me:

Global $sIPConfigTemp = @TempDir & "\IPConfig.txt"
    RunWait(@ComSpec & " /c IPConfig>" & $sIPConfigTemp, "", @SW_HIDE)
Global $iPing = 4
Global $sIPConfigRead = FileRead($sIPConfigTemp)
Global $sIPGateway = InputBox("Please enter Default Gateway", $sIPConfigRead, "", "", 400, 850, -1, -1)
Global $sIPGatewayTemp = @TempDir & "\IPGateway.txt"
    RunWait(@ComSpec & " /c ping -n " & $iPing & " " & $sIPGateway & ">" & $sIPGatewayTemp, "", @SW_HIDE)
    ShellExecute($sIPConfigTemp)
    ShellExecute($sIPGatewayTemp)

 

Link to comment
Share on other sites

after taking out the

Global $iPing = 4

so it would work with the rest of the script, it does not do what I wanted, I needed it to output to the screen AND to a file so it can be saved (showing all the lines of the test if the lines exceed screen size, such as doing longer tests. the code I posted on the OP works but breaks if the user presses the enter key after entering the gateway IP.

 

Link to comment
Share on other sites

it works, however, I need the output that is onscreen to show right away, such as doing a standard ping test in CMD. we regularly do tests over 100 lines+ and dont want to have to wait for the test to be done to be able to see what is going on, that is why I have been doing the test twice, once showing the on screen test, while in the background (in a hidden window) one with the output directed to a file.

I can send you the source code directly if you would be willing to help, just didn't want to blast it online.

Link to comment
Share on other sites

As mentioned it would be better to check to see what $dgate is returning, it should be in the format of x.x.x.x so you could use a custom function for example:

$dgate = _IPAddressInput("Please enter Default Gateway", $ipconfigread, "", "", 400, 850, -1, -1)

Func _IPAddressInput($_sTitle = "", $_sText = "", $_sDefault = "", $_sPassword = "", $_iWidth = 250, $_iHeight = 190, $_iLeft = Default, $_iTop = Default, $_iTimeout = 0, $_hWnd = Default)
    Local $sInputBox = InputBox($_sTitle, $_sText, $_sDefault, $_sPassword, $_iWidth, $_iHeight, $_iLeft, $_iTop, $_iTimeout, $_hWnd)
    If StringRegExp($sInputBox, "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", 3) Then
        $sInputBox = _IPAddressInput($_sTitle, $_sText & @CRLF & "Enter IP Address", $_sDefault, $_sPassword, $_iWidth, $_iHeight, $_iTop, $_iTimeout, $_hWnd)
    EndIf
    Return $sInputBox
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...