gil900

SciTE Console: _cin _cout for SciTE Console [ConsoleIn (!!) , ConsoleOut , ConsoleClean ..]

3 posts in this topic

#1 ·  Posted (edited)

Hello,
This udf open for you the ability to not only write in the console (in SciTE),
It allows you to write inputs in the console.

In other words:
It is exactly like the cin function
in C++ (in namespace std) and it works on SciTE and it is better.


Example 1:
output_Eou0tV.gif.e12ce5d33a6bf29350de02

Example 2:

output_mxi55n.gif.5255187e01295a62e7f80f

 

 

Example 1 code:

#include 'SciTE Console.au3'


HotKeySet('{ESC}','Exit1')


_ConsoleClean()


Local $sTitle = 'Hello World!'
Local $sText = 'Hello!'&@CRLF&'This is some saved text...'&@CRLF&'You can change me if you want!'

_cout('Hello! what do you want to do now?')
_cout('1 = print/edit variables , 2 = change console settings , 3 = clean the console , 4 = exit')

While 1


    ;
    Switch Number(_cin(1))
        Case 1
            _cout(' -> print/edit variables:',1)
            While 1
                _cout('Enter 1.1 to show variables, 1.2 to edit them, 1.3 to exit this mode:')
                Switch Number(_cin())
                    Case 1.1
                        _cout('The string value of $sTitle is: '&$sTitle,2)
                        _cout('The string value of $sText is:')
                        _cout($sText,2)

                    Case 1.2
                        _cout('Enter some text for $sTitle: ',0)
                        $sTitle = _cin()
                        _cout('The text of $sTitle is: '&$sTitle)

                        _cout('Enter some text for $sText. Write "@@@" to finish (you can use enter now). :')
                        $sText = _cin(1,'@@@')
                        _cout('')
                        MsgBox(0,'The text is',$sText)

                    Case 1.3
                        _cout('Exited')
                        ExitLoop

                    Case Else
                        _cout('You must enter only 1.1-1.3')
                EndSwitch

            WEnd

        Case 2
            _cout(' -> Do you want to always show the line number? select y for yes, n for no: ',0)
            If _cin(1) = 'y' Then
                $gg_sc_bPrintLine = True
            Else
                $gg_sc_bPrintLine = False
            EndIf

            _cout('')

            _cout("Enter the writing speed (10 is recommended!). use 0 for instantaneous speed. WARNING: don't use big number!! : ",0)
            $gg_sc_iWriteSpeed = Int(Number(_cin()))
            _cout('Write speed set to '&$gg_sc_iWriteSpeed)
            _cin('Settings saved.')

        Case 3
            ;~          Sleep(100)
            _ConsoleClean()
        Case 4
            _cout(' -> Are you sure? Select y/Y for yes, n/N for no: ',0)
            While 1
                Switch _cin(1)
                    Case 'y','Y'
                        _cout(' -> Exiting...')
                        Sleep(500)
                        Exit
                    Case 'n','N'
                        _cout('',1,@CRLF)
                        ExitLoop
                    Case Else
                        _cout(@CRLF&' -> You must enter y/Y or n/N. Select y/Y for yes, n/N for no: ',0)
                EndSwitch
            WEnd
        Case Else
            _cout(@CRLF&'You can enter only 1-4')
    EndSwitch
WEnd












Func Exit1()
    Exit
EndFunc

 

Example 2 code (Ported from _GUIConsole) :

#include 'SciTE Console.au3'


HotKeySet('{ESC}','Exit1')

; Clean the console
_ConsoleClean()


$gg_sc_iWriteSpeed = 15 ; Set the write speed to 15 (Read more in "ARIABLES FOR THE USER" in SciTE Console.au3)

; Print some text
_cout('Some text 1 ...');,$iAddLines = 1,$sAddChar = @CRLF)

Sleep(500)
; Print some text
_cout('Some text 2 ...')

Sleep(500)

_cout('After this text there is 3 @CRLF',3)

Sleep(500)

_cout('See?')

Sleep(1000)

_cout('After this text there is 3 @TAB',3,@TAB)

Sleep(500)

_cout('See?',2)

Sleep(1000)

_cout('Now I will clean this console and write some new text...')

Sleep(1500)

; Clean the Console
_ConsoleClean()

Sleep(500)

; Create the Console GUI
; Print some text
_cout('Some text 1 ...');,$iAddLines = 1,$sAddChar = @CRLF)

Sleep(500)
; Print some text
_cout('Some text 2 ...')


While Sleep(100)
WEnd



#Region functions
Func Exit1()
    Exit
EndFunc

#EndRegion

 

UDF Download:
SciTE Console v1 (by gil900).rar

 

 

 

Edited by gil900
2 people like this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Updated: added example for _cout (ported example from _GUIConsole)

Edited by gil900

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I developed a more modular way  of how to create each console "dialog"
I try to think of an concept that make it easy to implement under the Autoit limitation that is it is missing multi thread option.

There is good way to handle and create multiple GUIs, in one While loop.. but how you do it with console like this (in one While loop) ?  That's what I'm trying to solve.

 

this is what i come with:

Example:

#include 'SciTE Console.au3'
#include 'Console.au3'

HotKeySet('{ESC}','Exit1')





_ConsoleClean()





;~ Exit

Local $sTitle = 'Hello World!'
Local $sText = 'Hello!'&@CRLF&'This is some saved text...'&@CRLF&'You can change me if you want!'

;~ _cout('Hello! what do you want to do now?')
;~ _cout('1 = print/edit variables , 2 = change console settings , 3 = clean the console , 4 = exit')



HomeOptions()


Func HomeOptions()
    _cout('1 = print/edit variables , 2 = change console settings'); , 3 = clean the console , 4 = exit')

    _Console_UnRegisterAllInputs()

    _Console_RegisterInput('1',HomeOptions_PrintOrEditVars)
    _Console_RegisterInput('2',HomeOptions_ChangeConsoleSettings)


EndFunc

#Region HomeOptions_PrintOrEditVars_*

    Func HomeOptions_PrintOrEditVars()
        _cout(' -> print/edit variables:',1)
        _cout('Enter 1.1 to show variables, 1.2 to edit them, 1.3 to exit this mode:')

        _Console_UnRegisterAllInputs()

        _Console_RegisterInput('1.1',HomeOptions_PrintOrEditVars_Option_1d1)
        _Console_RegisterInput('1.2',HomeOptions_PrintOrEditVars_Option_1d2)
        _Console_RegisterInput('1.3',HomeOptions_PrintOrEditVars_Option_1d3)

    EndFunc

    ; OPTIONS:
        Func HomeOptions_PrintOrEditVars_Option_1d1()
            _cout('The string value of $sTitle is: '&$sTitle,2)
            _cout('The string value of $sText is:')
            _cout($sText,2)
        EndFunc


        Func HomeOptions_PrintOrEditVars_Option_1d2()
            _cout('Enter some text for $sTitle: ',0)
            $sTitle = _cin()
            _cout('The text of $sTitle is: '&$sTitle)

            _cout('Enter some text for $sText. Write "@@@" to finish (you can use enter now). :')
            $sText = _cin(1,'@@@')
            _cout('')
            MsgBox(0,'The text is',$sText)

        EndFunc


        Func HomeOptions_PrintOrEditVars_Option_1d3()
            _cout('Exited')
            HomeOptions()


        EndFunc

#EndRegion


#Region ChangeConsoleSettings_*
    Func HomeOptions_ChangeConsoleSettings()
        _Console_UnRegisterAllInputs()
        _cout('HomeOptions_ChangeConsoleSettings.',1)
        _cout('q = exit',1)
        _Console_RegisterInput('q',HomeOptions_ChangeConsoleSettings_exit)

    EndFunc

    Func HomeOptions_ChangeConsoleSettings_exit()
        HomeOptions()
    EndFunc
#EndRegion





While Sleep(10)

    _Console_ProcessRegisteredInputs(_cin(1))


WEnd



#cs OLD CODE

While 1


    ;
    Switch Number(_cin(1))
        Case 1
            _cout(' -> print/edit variables:',1)
            While 1
                _cout('Enter 1.1 to show variables, 1.2 to edit them, 1.3 to exit this mode:')
                Switch Number(_cin())
                    Case 1.1
                        _cout('The string value of $sTitle is: '&$sTitle,2)
                        _cout('The string value of $sText is:')
                        _cout($sText,2)

                    Case 1.2
                        _cout('Enter some text for $sTitle: ',0)
                        $sTitle = _cin()
                        _cout('The text of $sTitle is: '&$sTitle)

                        _cout('Enter some text for $sText. Write "@@@" to finish (you can use enter now). :')
                        $sText = _cin(1,'@@@')
                        _cout('')
                        MsgBox(0,'The text is',$sText)

                    Case 1.3
                        _cout('Exited')
                        ExitLoop

                    Case Else
                        _cout('You must enter only 1.1-1.3')
                EndSwitch

            WEnd

        Case 2
            _cout(' -> Do you want to always show the line number? select y for yes, n for no: ',0)
            If _cin(1) = 'y' Then
                $gg_sc_bPrintLine = True
            Else
                $gg_sc_bPrintLine = False
            EndIf

            _cout('')

            _cout("Enter the writing speed (10 is recommended!). use 0 for instantaneous speed. WARNING: don't use big number!! : ",0)
            $gg_sc_iWriteSpeed = Int(Number(_cin()))
            _cout('Write speed set to '&$gg_sc_iWriteSpeed)
            _cin('Settings saved.')

        Case 3
            ;~          Sleep(100)
            _ConsoleClean()
        Case 4
            _cout(' -> Are you sure? Select y/Y for yes, n/N for no: ',0)
            While 1
                Switch _cin(1)
                    Case 'y','Y'
                        _cout(' -> Exiting...')
                        Sleep(500)
                        Exit
                    Case 'n','N'
                        _cout('',1,@CRLF)
                        ExitLoop
                    Case Else
                        _cout(@CRLF&' -> You must enter y/Y or n/N. Select y/Y for yes, n/N for no: ',0)
                EndSwitch
            WEnd
        Case Else
            _cout(@CRLF&'You can enter only 1-4')
    EndSwitch
WEnd

#ce










Func Exit1()
    Exit
EndFunc

 

And the new UDF I just made - Console.au3. I have no idea how to call it.

Global Enum _
    $__Console_aInputs_idx2_sHotString, _
    $__Console_aInputs_idx2_Func, _
    $__Console_aInputs_idx2max

Global $__Console_aInputs[1][$__Console_aInputs_idx2max]







Func _Console_RegisterInput($sHotString,$Function)
    ; Look for the function index
    Local $iFuncIndex
    For $a = 1 To $__Console_aInputs[0][0]
        If $__Console_aInputs[$a][$__Console_aInputs_idx2_Func] <> $Function Then ContinueLoop
        $iFuncIndex = $a
    Next

    If Not $iFuncIndex Then
        $__Console_aInputs[0][0] += 1
        ReDim $__Console_aInputs[$__Console_aInputs[0][0]+1][$__Console_aInputs_idx2max]
        $iFuncIndex = $__Console_aInputs[0][0]
    EndIf

    $__Console_aInputs[$iFuncIndex][$__Console_aInputs_idx2_sHotString] = $sHotString
    $__Console_aInputs[$iFuncIndex][$__Console_aInputs_idx2_Func] = $Function

EndFunc

Func _Console_ProcessRegisteredInputs(ByRef $sInput)
    ;If Not $__Console_aInputs[0][0] Then Return

    For $a = 1 To $__Console_aInputs[0][0]
        If $sInput <> $__Console_aInputs[$a][$__Console_aInputs_idx2_sHotString] Then ContinueLoop
        Return $__Console_aInputs[$a][$__Console_aInputs_idx2_Func]()
    Next

EndFunc



Func _Console_UnRegisterAllInputs()
    ReDim $__Console_aInputs[1][$__Console_aInputs_idx2max]
    $__Console_aInputs[0][0] = 0
EndFunc

 

Edited by gil900

Share this post


Link to post
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

  • Similar Content

    • Hoth2001
      By Hoth2001
      I installed AutoIt to my computer 3 days ago...and have invested the last 3 days learning how to use it.
      As learned in the tutorials, whenever opening I new file in Scite editor I'd immediatley save the file
      I left the Scite Editor open for the past 3 consecutive days on my laptop
       
      No problem
       
      Today I closed Autoit for the first time, restarted my computer, and opened up the Scite Editor
      Now whenever I try to save a file I am prevented from doing so because I apparently don't have permission!?  
      And whenever I try to run any of the programs I've created over the past 3 days now I keep getting annoying popup notifications before I run them
       
      Problem
       
      To go around the issue, I copied a program originally saved in the AUtoIt folder to another folder (since I was barred from saving it in it's original AutoIt location)
      NOw when I run the code the mouse coordiantes are all off
      and I still get that pesky notification whenever I try to run a program
       
      Big Problem!!!
      Anyone have any clue why I'm going through this BS?
       
      1. I checked my User settings and YES I am the administrator on this cpu
      2. I tried to de-select the "read only" attribute for the AutoIt folder (everytime after doing this successfully the folder immediately and automatically reverts back to "read only")
       
      Any help would be MOST appreciated. I've attached screen shots of the annoying bus I keep getting
       
       


    • algiuxas
      By algiuxas
      Hello everybody!
      I get these weird errors in SciTE console:
      [0801/210405:ERROR:tcp_socket_win.cc(335)] bind() returned an error: Only one usage of each socket address (protocol/network address/port) is normally permitted. (0x2740) [0801/210405:ERROR:devtools_http_handler.cc(229)] Cannot start http server for devtools. Stop devtools. [0801/210405:ERROR:browser_gpu_channel_host_factory.cc(119)] Failed to launch GPU process. [0801/210405:ERROR:browser_gpu_channel_host_factory.cc(119)] Failed to launch GPU process. My script:
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #NoTrayIcon $title = "Hello" $txt = "..." ; TODO: Make 4 of them ;~ #Region ### START Koda GUI section ### Form= ;~ $1_GUI = GUICreate($title, 370, 120, -1, -1) ;~ GUISetBkColor(0xFFFFFF) ;~ $1_B1 = GUICtrlCreateButton("B1", 136, 80, 107, 25) ;~ GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") ;~ $1_B2 = GUICtrlCreateButton("B2", 248, 80, 107, 25) ;~ GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") ;~ GUICtrlCreateLabel($txt, 16, 24, 338, 52) ;~ GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;~ GUICtrlSetColor(-1, 0x000000) ;~ GUISetState(@SW_SHOW) ;~ #EndRegion ### END Koda GUI section ### #Region ### START Koda GUI section ### Form= $2_GUI = GUICreate($title, 370, 0?"Hi :)":120, -1, -1) GUISetBkColor(0xFFFFFF) $2_B1 = GUICtrlCreateButton("B1", 136, 80, 107, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $2_B2 = GUICtrlCreateButton(0?":D":"B2", 248, 80, 107, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlCreateLabel($txt, 16, 24, 338, 52) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $u32dll = DllOpen("user32.dll") ;~ Opt("GUIOnEventMode", 1) ;~ GUICtrlSetOnEvent(-3, "_Exit") ; TODO: Fix, doesn't work with 2 GUI at the same time ;~ GUICtrlSetOnEvent($B11, "_Exit") ;~ GUICtrlSetOnEvent($B21, "_Exit") ;~ GUICtrlSetOnEvent($B12, "_Exit") ;~ GUICtrlSetOnEvent($B22, "_Exit") ;~ $pos1 = WinGetPos($GUI1) ;~ $pos2 = WinGetPos($GUI1) While 1 ;~ $pos1 = WinGetPos($GUI1) ;~ $pos2 = WinGetPos($GUI1) ;~ $x = $pos1[0] - 370 ;~ $y = $pos1[1] ;~ WinMove($GUI2, "", $x, $y, $pos1[2], $pos1[3], 1) ; Press middle mouse button to close (it's gonna be a non malicious prank for my friend) If _IsPressed(4, $u32dll) Then Exit $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() ;~ Case $1_B1 ;~ _Exit() ;~ Case $1_B2 ;~ _Exit() Case $2_B1 _Exit() Case $2_B2 _Exit() EndSwitch WEnd Func _Exit() ; TODO: ... ;~ GUIDelete($1_GUI) GUIDelete($2_GUI) Exit EndFunc ;==>_Exit How to get rid of these errors?
    • Nareshm
      By Nareshm
      I create message box but i dont know how to add button action when i click it.

      Help for : Add script for Button : Left, Right, Right Finger
      example when i press Left finger button do Case $idNotepad
                      $iPID = WinActivate ( " :PS :: Version - 2.8.0.0  - [eFS Bill]")
                              ControlSend(" :DS  - eF :: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:btnReset]", "{esc}")
                              ControlClick ( " :DS  - eF :: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:txtrdNo]")
                              ControlSend(" :DS  - eF:: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:txtrdNo]", "^v")
                              ControlSend(" :DS  - eF :: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:txtrdNo]", "{enter}")
      How to add like above ?
                    
                                                                sorry for my bad english
       
    • Altor
      By Altor
      Hi all:
      In Scite it is possible to expand and collapse  all  the #Region at time  with a shortcut ..?
      Now I use the + key to expand and collapse but I can only use this suggestion for a one # Region
      If I collapse all the regions one by one  in order to have the code more understandable when I re-open the script all the regions are expanded and I need to collapse all again one by one.
      Thank.s to all
      Altor
    • corgano
      By corgano
      Edit: A solution was found! Thanks Jos and others who helped me find this:
      You can have AutoIt run a different "Main" autoit script when you hit F5 instead of the current one, per folder, by doing the following:
      Run SciTE (might need administrator, depending on how autoit was installed) Options -> global properties (alt o g) Uncomment properties.directory.enable=1 (line 270 in my case) create a file SciTEDirectory.properties in the project's main folder Alternatively, if you don't have admin or don't want to edit the global.properties for whatever reason, you can just skip step 1,2,3 and name it SciTE.properties Put in the file you created command.go.$(au3)="$(SciteDefaultHome)\..\AutoIt3.exe" "$(SciteDefaultHome)\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "NAME OF SCRIPT HERE.au3" /UserParams $(1) $(2) $(3) $(4) Save the file. Now anything you run in that folder or subfolder will run the main script when you hit F5 Using SciTEDirectory.properties effects that folder and subfolders, where as SciTE.properties only effects that folder. Apart from that they work the same

      Original question:
      I have a main script, and a bunch of includes / udf's. Almost every single time I edit my includes I hit F5 to run the script, but it runs the include instead. I'm tired of switching back to the main script's tab in SciTE to run it, just to switch back to the include. Is there some kind of #flag or option to set a "main au3 file" so when I hit F5, it will see that and run the main file instead?