Jump to content

need help here


au3scr
 Share

Recommended Posts

Mmmm... I'm not sure I understand your question. If you want to get the text from an input, use:

GuiCtrlRead()

Here's something I made for fun:

#include <GUIConstants.au3>
#include <GUIEdit.au3>
Opt("RunErrorsFatal",0)
HotKeySet("{enter}","read_func")
$line=1
$Form1 = GUICreate("Terminal", 499, 274, 201, 116)
GUISetCursor (7)
$CommandInput = GUICtrlCreateEdit("", 0, 0, 497, 273, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "Shell:")
GUICtrlSetFont(-1, 10, 500, 0, "Terminal")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func read_func()
    $Input=_GUICtrlEditGetLine($CommandInput,$line)
    $command=StringTrimLeft($Input,6)
    $Say=StringInStr($command,"say")
    $Exit=StringInStr($command,"exit")
    $run=StringInStr($command,"run")
    If $Say Then
        HotKeySet("{enter}")
        $string=StringTrimLeft($Input,10)
        Send(@CRLF&$string&@CRLF&"shell:")
        $line=$line+4
        Sleep(100)
        HotKeySet("{enter}","read_func")
    Else
        If $Exit Then
            Exit
        Else  
        if $run Then  
            HotKeySet("{enter}")
            $string=StringTrimLeft($Input,10)
            Send(@CRLF&"running "&$string&"..."&@CRLF&"Shell:")
            $line=$line+4
            Sleep(100)
            HotKeySet("{enter}","read_func")            
            run($string)
            if @error Then
                HotKeySet("{enter}")
                $string=StringTrimLeft($Input,10)
                Send(@CRLF&"FATAL ERROR: could not find external program"&"..."&@CRLF&"Shell:")
                $line=$line+4
                Sleep(100)
                HotKeySet("{enter}","read_func")
            EndIf
                
        Else
        HotKeySet("{enter}")
        Send(@CRLF&"'"&$command&"'"&"is not a valid command"&@CRLF&"Shell:")
        $line=$line+4
        Sleep(100)
        HotKeySet("{enter}","read_func")
    EndIf
    EndIf
    EndIf
EndFunc

Posted Image

It kinda looks like cmd and it can recognize three commands:

say [whatever you want to say]

exit

run [path or name of the external program]

Please notice that I set the enter key as a hot key and it won't work in other applications until you close it.

I suggest you download Koda for designing your GUI's. It's awesome.

Edited by Nahuel
Link to comment
Share on other sites

thanks for this script now i modifyied it and I tryed add new command sys

but if i type it then it says "is not a valid command"

#include <GUIConstants.au3>
#include <GUIEdit.au3>
HotKeySet("{enter}","read_func")
$line=1
$Form1 = GUICreate("Terminal", 499, 274, 201, 116)
GUISetCursor (7)
$CommandInput = GUICtrlCreateEdit("", 0, 0, 497, 273, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "shell:")
GUICtrlSetFont(-1, 10, 500, 0, "Terminal")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func read_func()
    $Input=_GUICtrlEditGetLine($CommandInput,$line)
    $command=StringTrimLeft($Input,9)
    $Say=StringInStr($command,"say")
    $Exit=StringInStr($command,"exit")
    $sysinf=StringInStr($command,"sys")
    If $Say Then
        HotKeySet("{enter}")
        $string=StringTrimLeft($Input,13)
        Send(@CRLF&$string&@CRLF&"command~>")
        $line=$line+4
        Sleep(100)
        HotKeySet("{enter}","read_func")
    Else
        If $Exit Then
            Exit
        Else  
        if $sys Then    
            run( @ScriptDir & "sysinf.exe")
        Else
        HotKeySet("{enter}")
        Send(@CRLF&"'"&$command&"'"&"is not a valid command"&@CRLF&"command~>")
        $line=$line+4
        Sleep(100)
        HotKeySet("{enter}","read_func")
    EndIf
    EndIf
    EndIf
EndFunc

how i add command?

And other question : how i can add colors on script code?

I am new thats why i have silly questions but time makes me better

Edited by au3scr
Link to comment
Share on other sites

It's because you changed "command~>" by "Shell:". Notice this line:

$command=String TrimLeft($Input,9)
this 'cuts' nine characters from the left, leaving the command alone. If you change "command~>" by "Shell:", now it has to trim only 6 characters:

$command=String TrimLeft($Input,6)

Here it's fixed:

#include <GUIConstants.au3>
#include <GUIEdit.au3>
Hotkeys("{enter}","read_func")
$line=1
$Form1 = GUICreate("Terminal", 499, 274, 201, 116)
GUISetCursor (7)
$Command Input = GUICtrlCreateEdit("", 0, 0, 497, 273, BitORES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "shell:")
GUICtrlSetFont(-1, 10, 500, 0, "Terminal")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit

    End Switch
Wend

Func read_func()
    $Input=_GUICtrlEditGetLine($Command Input,$line)
    $command=String TrimLeft($Input,6)
    $Say=String InStr($command,"say")
    $Exit=String InStr($command,"exit")
    $sysinfo=String InStr($command,"sys")
    If $Say Then
        Hotkeys("{enter}")
        $string=String TrimLeft($Input,10)
        Send(@CRLF&$string&@CRLF&"shell:")
        $line=$line+4
        Sleep(100)
        Hotkeys("{enter}","read_func")
    Else
        If $Exit Then
            Exit
        Else  
        if $sysinfo Then    
            run( @ScriptDir & "sysinf.exe")
        Else
        Hotkeys("{enter}")
        Send(@CRLF&"'"&$command&"'"&"is not a valid command"&@CRLF&"command~>")
        $line=$line+4
        Sleep(100)
        Hotkeys("{enter}","read_func")
    EndIf
    EndIf
    EndIf
EndFunc

And what do you mean 'add colors'? You can set the font color of the edit control with this:

GUICtrlSetColor($CommandInput, 0xFFFFFF)

That makes the font white. Use the hex code of any other color that you want.

And download Koda, it will help you a lot!

here: http://www.autoitscript.com/forum/index.php?showtopic=32299

Always refer to help file as well, all your questions may be answered there.

Edited by Nahuel
Link to comment
Share on other sites

Look, I added the run command:

#include <GUIConstants.au3>
#include <GUIEdit.au3>
Opt("RunErrorsFatal",0)
HotKeySet("{enter}","read_func")
$line=1
$Form1 = GUICreate("Terminal", 499, 274, 201, 116)
GUISetCursor (7)
$CommandInput = GUICtrlCreateEdit("", 0, 0, 497, 273, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "Shell:")
GUICtrlSetFont(-1, 10, 500, 0, "Terminal")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func read_func()
    $Input=_GUICtrlEditGetLine($CommandInput,$line)
    $command=StringTrimLeft($Input,6)
    $Say=StringInStr($command,"say")
    $Exit=StringInStr($command,"exit")
    $run=StringInStr($command,"run")
    If $Say Then
        HotKeySet("{enter}")
        $string=StringTrimLeft($Input,10)
        Send(@CRLF&$string&@CRLF&"shell:")
        $line=$line+4
        Sleep(100)
        HotKeySet("{enter}","read_func")
    Else
        If $Exit Then
            Exit
        Else  
        if $run Then  
            HotKeySet("{enter}")
            $string=StringTrimLeft($Input,10)
            Send(@CRLF&"running "&$string&"..."&@CRLF&"Shell:")
            $line=$line+4
            Sleep(100)
            HotKeySet("{enter}","read_func")            
            run($string)
            if @error Then
                HotKeySet("{enter}")
                $string=StringTrimLeft($Input,10)
                Send(@CRLF&"FATAL ERROR: could not find external program"&"..."&@CRLF&"Shell:")
                $line=$line+4
                Sleep(100)
                HotKeySet("{enter}","read_func")
            EndIf
                
        Else
        HotKeySet("{enter}")
        Send(@CRLF&"'"&$command&"'"&"is not a valid command"&@CRLF&"Shell:")
        $line=$line+4
        Sleep(100)
        HotKeySet("{enter}","read_func")
    EndIf
    EndIf
    EndIf
EndFunc

Examples:

run notepad

run C:\Windows\System32\cmd.exe

Link to comment
Share on other sites

tnx for script put it exits when i type commant sys

This is sysinf.exe

run("notepad")
$VOL = DriveGetLabel("C:\")
$SERIAL = DriveGetSerial("C:\")
$TOTAL = DriveSpaceTotal("C:\")
$FREE = DriveSpaceFree("C:\")
$FS = DriveGetFileSystem ("C:\")
WinWaitActive("Untitled - Notepad")
WinSetTitle("Untitled - Notepad","","system")
ClipPut("monitor:")
send("^v{enter}")
ClipPut("Ekraanilaius: " & @DesktopWidth)
send("^v{enter}")
ClipPut("Ekraanikõrgus: " & @DesktopHeight)
send("^v{enter}")
ClipPut("Ekraanivärskendus: " & @DesktopRefresh)
send("^v{enter}")
ClipPut("Ekraanivärvisügavus: " & @DesktopDepth)
send("^v{enter}")
ClipPut("Arvuti ja süsteem")
send("^v{enter}")
ClipPut("Süsteemi keel: " & @OSLang)
send("^v{enter}")
ClipPut("Süsteem_tüüp: " & @OSTYPE)
send("^v{enter}")
ClipPut("Süsteem_versioon: " & @OSVersion)
send("^v{enter}")
ClipPut("Süsteem_ehitus: " & @OSBuild)
send("^v{enter}")
ClipPut("Süsteem_SP: " & @OSServicePack)
send("^v{enter}")
ClipPut("Klaviatuuri paigutus: " & @KBLayout)
send("^v{enter}")
ClipPut("Protsessori arhidektuur: " & @ProcessorArch)
send("^v{enter}")
ClipPut("Arvuti nimi: " & @ComputerName)
send("^v{enter}")
ClipPut("Hetkel aktiivne kasutaja: " & @UserName)
send("^v{enter}")
ClipPut("windows on kataloogis: " & @WindowsDir)
send("^v{enter}")
ClipPut("Windows on kettal: " & @HomeDrive)
send("^v{enter}")
ClipPut("Kasutaja profiilid: " & @UserProfileDir)
send("^v{enter}")
ClipPut("start menüü: " & @StartMenuDir)
send("^v{enter}")
ClipPut("töölaua asukoht: " & @DesktopDir)
send("^v{enter}")
ClipPut("start menüü: " & @StartMenuDir)
send("^v{enter}")
ClipPut("ketta C:\ nimetus: " & $VOL)
send("^v{enter}")
ClipPut("ketta C:\ kogu suurus: " & $Total)
send("^v{enter}")
ClipPut("ketta C:\ vabaruum: " & $FREE)
send("^v{enter}")
ClipPut("ketta C:\ serialli nr: " & $SERIAL)
send("^v{enter}")
ClipPut("ketta C:\ failisüsteem: " & $FS)
send("^v{enter}")
ClipPut("IP aadress on: " & @IPAddress1 )
send("^v{enter}")
Edited by au3scr
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...