Jump to content

Possible to execute autoit commands through an input box?


Recommended Posts

Like let's say you make a gui with an input box and a button in the middle. You type Exit in the input box, and click the button, then the au3 script exits. Or you make a msgbox, or change varibles from the box for debugging purposes.

Is something like this possible.

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Heres how i would propably do it 8) (didnt test it thought so it might bug a lil) :

Opt("GUICloseOnESC", 1)

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

Global $Line = 0

$Title_GUI = "Test GUI"
$Main_GUI = GUICreate($Title_GUI, 300, 200)
$Edit_GUI = GUICtrlCreateEdit( "", 10, 0, 280, 150, $ES_READONLY)
$Input_GUI = GUICtrlCreateInput("", 10, 160, 250, 20)
$Button_GUI = GUICtrlCreateButton("OK", 170, 160, 20, 30) 
GUI_Log("GUI example", $Edit_GUI)
GUI_Log("try typing /test or /exit 8)", $Edit_GUI)

While 1
    $Msg = GUIGetMsg()
    
    Select 
        Case $Msg = $Button_GUI
            $Input = GUICtrlRead($Input_GUI)
            Select 
                Case $Input = "/Test"
                    MsgBox(0, "Test", "Msgbox executed from gui")
    
                Case $Input = "/Exit"
                    MsgBox(0, "Test", "Example will exit now")
                    Exit
            EndSelect
            
        Case _IsPressed("0D") AND WinActive($Title_GUI)
            $Input = GUICtrlRead($Input_GUI)
            If $Input <> "" Then 
                Select 
                    Case $Input = "/Test"
                        MsgBox(0, "Test", "Msgbox executed from gui")
    
                    Case $Input = "/Exit"
                        MsgBox(0, "Test", "Example will exit now")
                        Exit
                EndSelect
    
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
        
    EndSelect
WEnd


Func GUI_Log($TXT, $CID)
    Local $Date = @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & ":" & @SEC & " > "

    $Line += 1
    GUICtrlSetData($CID, $Date & $TXT & @CRLF, $Line)
EndFunc
Link to comment
Share on other sites

There was serval ways you can do this, all depends what you want to do.

If you want your 'own' piece of commands, Example A is best for you.

If you want predefined AutoIt functions, look at Example B.

-------------------------------------------------------------------------------------------------------

EXAMPLE A:

While 1
Switch InputBox("Hello","Enter command")
    Case "exit"
        Exit
    Case "hi"
        MsgBox(64,"Commander","hi")
    Case "" ;here enter your command
    ;;;;;;;
    Case Else ;what if user enters unexpected command...
    ;;;;;;;
EndSwitch
Wend
;this uses betaoÝ÷ ØEÀ0òÄ«­¢+Ù]¡¥±Ä(ÀÌØí½µµ¹õ%¹ÁÕÑ   ½à ÅÕ½Ðí
½µµ¹ÈÅÕ½Ðì°ÅÕ½Ðí!¤¸¹ÑÈÁÉ¥¹Õѽ%нµµ¹¡É¸ÅÕ½Ðì¤)áÕÑ ÀÌØí½µµ¹¤)]¹(íÑ¡¥ÌÕÍÌѱͼ

i542

I can do signature me.

Link to comment
Share on other sites

  • Moderators

This would be another way.

#include <GuiConstants.au3>

Opt("GuiOnEventMode", True)

$GUI = GUICreate("Test", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Input = GUICtrlCreateInput("", 10, 10, 180)
$Button = GUICtrlCreateButton("Execute", 10, 40, Default, Default, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent($Button, "_Execute")
$Label = GUICtrlCreateLabel("Return: ", 10, 75, 180)
GUISetState()

While 1
    Sleep(10)
WEnd

Func _Execute()
    $sCommand = GUICtrlRead($Input)
    $vRet = Execute($sCommand)
    If Not @error Then
        GUICtrlSetData($Label, "Return: " & $vRet)
    Else
        GUICtrlSetData($Label, "Error: " & @error)
    EndIf
EndFunc   ;==>_Execute

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

I found this to be interesting (or possibly I'm doing something wrong).

Dim $LineOfCode[15]
   $f = @DesktopDir & "\SampleDialog.txt"
   $c = _FileCountLines($f)
   
   For $a = 1 To $c
     $LineOfCode[$a] = FileReadLine($f,$a)
     Execute($LineOfCode[$a])
   NextoÝ÷ Ù8b±Ú²}ý·
+ë"­µ§!éí

but this does.... :whistle:

SampleDialog.txt

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

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...