Shaggi Posted June 25, 2012 Author Share Posted June 25, 2012 (edited) Ok then... How does cls do it? After all, cls is just a program using the same api as we have available to us Granted my solution is 100 lines longer, but if you are interested in how to do it properly then: expandcollapse popup#AutoIt3Wrapper_Change2CUI=y For $i = 1 to 9 ConsoleWrite("This is line " & $i & "." & @LF) Sleep(500) if $i = 5 Then _Console_Clear() Sleep(500) EndIf Next Func _Console_Clear($hConsoleOutput = -1) Local $aiSize If $hConsoleOutput = -1 Then $hConsoleOutput = _Console_GetStdHandle() $aiSize = _Console_GetScreenBufferSize($hConsoleOutput) _Console_FillOutputCharacter($hConsoleOutput, " ", $aiSize[0] * $aiSize[1]) _Console_SetCursorPosition($hConsoleOutput, 0, 0) Return EndFunc Func _Console_SetCursorPosition($hConsoleOutput, $iX, $iY) Local $iCursorPosition, $aResult If $hConsoleOutput = -1 Then $hConsoleOutput = _Console_GetStdHandle() $iCursorPosition = BitShift($iY, -16) + $iX $aResult = DllCall("kernel32.dll", "bool", "SetConsoleCursorPosition", _ "handle", $hConsoleOutput, _ "int", $iCursorPosition) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] <> 0 EndFunc ;==>_Console_SetCursorPosition Func _Console_FillOutputCharacter($hConsoleOutput, $sCharacter, $nLength, $iX = 0, $iY = 0) Local $aResult, $tCOORD If $hConsoleOutput = -1 Then $hConsoleOutput = _Console_GetStdHandle() If IsString($sCharacter) Then $sCharacter = AscW($sCharacter) $tCOORD = BitShift($iY, -16) + $iX $aResult = DllCall("kernel32.dll", "bool", "FillConsoleOutputCharacterW", _ "handle", $hConsoleOutput, _ "WORD", $sCharacter, _ "dword", $nLength, _ "int", $tCOORD, _ "dword*", 0) If @error Then Return SetError(@error, @extended, False) Return SetExtended($aResult[5], $aResult[0] <> 0) EndFunc ;==>_Console_FillOutputCharacter Func _Console_GetScreenBufferSize($hConsoleOutput = -1) Local $tConsoleScreenBufferInfo, $aRet[2] $tConsoleScreenBufferInfo = _Console_GetScreenBufferInfo($hConsoleOutput) If @error Then Return SetError(@error, @extended, 0) $aRet[0] = DllStructGetData($tConsoleScreenBufferInfo, "SizeX") $aRet[1] = DllStructGetData($tConsoleScreenBufferInfo, "SizeY") Return $aRet EndFunc ;==>_Console_GetScreenBufferSize Func _Console_GetScreenBufferInfo($hConsoleOutput = -1, $hDll = -1) Local $tConsoleScreenBufferInfo, $aResult Local Const $tagCONSOLE_SCREEN_BUFFER_INFO = "SHORT SizeX; SHORT SizeY; SHORT CursorPositionX;" & _ "SHORT CursorPositionY; SHORT Attributes; SHORT Left; SHORT Top; SHORT Right; SHORT Bottom;" & _ "SHORT MaximumWindowSizeX; SHORT MaximumWindowSizeY" If $hConsoleOutput = -1 Then $hConsoleOutput = _Console_GetStdHandle() $tConsoleScreenBufferInfo = DllStructCreate($tagCONSOLE_SCREEN_BUFFER_INFO) $aResult = DllCall("kernel32.dll", "bool", "GetConsoleScreenBufferInfo", _ "handle", $hConsoleOutput, _ "ptr", DllStructGetPtr($tConsoleScreenBufferInfo)) If @error Or (Not $aResult[0]) Then Return SetError(@error, @extended, 0) Return $tConsoleScreenBufferInfo EndFunc ;==>_Console_GetScreenBufferInfo Func _Console_GetStdHandle($nStdHandle = -11) Local $aResult $aResult = DllCall("kernel32.dll", "handle", "GetStdHandle", _ "dword", $nStdHandle) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc ;==>_Console_GetStdHandle Mostly lifted straight from my console UDF, I think most of those functions will now be available in WinAPIEx so will actually be standard AutoIt functions soon. Basically you fill the console with spaces and move the cursor to square one. You tell me One cannot know if cls has access to undocumented api. Anyway, thanks for the code. Although it looks a bit hacky, it actually seems to be the only way, besides switching buffers, cls & clrscr() (anyone know what exports this?) e: apparantly some ansi escape codes should do the trick, too. Edited June 25, 2012 by Shaggi Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
BrewManNH Posted June 26, 2012 Share Posted June 26, 2012 According to the MSDN site, they say to use system("cls") which is a system function or to do it progammatically use FillConsoleOutputCharacterW themselves, so it appears that is the best way to do it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
DJ VenGenCe Posted July 11, 2012 Share Posted July 11, 2012 Any idea how to push ANSI Screens (From old BBS Days) to this console? Link to comment Share on other sites More sharing options...
RevengeOfShadow Posted August 6, 2012 Share Posted August 6, 2012 (edited) I want to change the font of the console to "Lucida Console" (for a look-like MSysGit/Cygwin console), is it possible ? EDIT: And how to change title of window ? Because use "title" with "System()" put the title in CAPS. Edited August 6, 2012 by RevengeOfShadow Link to comment Share on other sites More sharing options...
Shaggi Posted August 6, 2012 Author Share Posted August 6, 2012 I want to change the font of the console to "Lucida Console" (for a look-like MSysGit/Cygwin console), is it possible ?EDIT: And how to change title of window ? Because use "title" with "System()" put the title in CAPS.I dont think you can do that, sorry. It's possible by rightclicking the icon on a running console, then settings - but i do think it's global for all consoles, then.Uploaded a new udf that supports non-capped titles, will probably be implemented as a function sometime. RevengeOfShadow 1 Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
RevengeOfShadow Posted August 10, 2012 Share Posted August 10, 2012 Is your console get property of CMD ? For example, if I set Lucida Console to all CMD, your console will have Lucida Console ? If yes, how to change CMD font to "Lucida Console" ? Thx. Link to comment Share on other sites More sharing options...
RevengeOfShadow Posted September 15, 2012 Share Posted September 15, 2012 I've found a method for set CMD to "Lucida Console" with a nice size ! Juste add this to your code start (Before first init of console) : Global $AUTREP = StringReplace(@AutoItExe,"","_") If Regread("HKEY_CURRENT_USERConsole" & $AUTREP,"FaceName") <> "Lucida Console" Then RegWrite("HKEY_CURRENT_USERConsole" & $AUTREP,"FaceName","REG_SZ","Lucida Console") RegWrite("HKEY_CURRENT_USERConsole" & $AUTREP,"FontFamily","REG_DWORD","0x00000036") RegWrite("HKEY_CURRENT_USERConsole" & $AUTREP,"FontSize","REG_DWORD","0x000e0000") RegWrite("HKEY_CURRENT_USERConsole" & $AUTREP,"FontWeight","REG_DWORD","0x00000190") EndIF It's not perfect, but it works fine ! Link to comment Share on other sites More sharing options...
MrKris7100 Posted March 23, 2013 Share Posted March 23, 2013 Welcome. How to execute commands in the library Console.au3 cmd from which it was run the same script AutoIt. Open 2 windows detected by the fact I'm not at hand. Of course, this can not be it: Ok then... How does cls do it? After all, cls is just a program using the same api as we have available to us Granted my solution is 100 lines longer, but if you are interested in how to do it properly then: expandcollapse popup#AutoIt3Wrapper_Change2CUI=y For $i = 1 to 9 ConsoleWrite("This is line " & $i & "." & @LF) Sleep(500) if $i = 5 Then _Console_Clear() Sleep(500) EndIf Next Func _Console_Clear($hConsoleOutput = -1) Local $aiSize If $hConsoleOutput = -1 Then $hConsoleOutput = _Console_GetStdHandle() $aiSize = _Console_GetScreenBufferSize($hConsoleOutput) _Console_FillOutputCharacter($hConsoleOutput, " ", $aiSize[0] * $aiSize[1]) _Console_SetCursorPosition($hConsoleOutput, 0, 0) Return EndFunc Func _Console_SetCursorPosition($hConsoleOutput, $iX, $iY) Local $iCursorPosition, $aResult If $hConsoleOutput = -1 Then $hConsoleOutput = _Console_GetStdHandle() $iCursorPosition = BitShift($iY, -16) + $iX $aResult = DllCall("kernel32.dll", "bool", "SetConsoleCursorPosition", _ "handle", $hConsoleOutput, _ "int", $iCursorPosition) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] <> 0 EndFunc ;==>_Console_SetCursorPosition Func _Console_FillOutputCharacter($hConsoleOutput, $sCharacter, $nLength, $iX = 0, $iY = 0) Local $aResult, $tCOORD If $hConsoleOutput = -1 Then $hConsoleOutput = _Console_GetStdHandle() If IsString($sCharacter) Then $sCharacter = AscW($sCharacter) $tCOORD = BitShift($iY, -16) + $iX $aResult = DllCall("kernel32.dll", "bool", "FillConsoleOutputCharacterW", _ "handle", $hConsoleOutput, _ "WORD", $sCharacter, _ "dword", $nLength, _ "int", $tCOORD, _ "dword*", 0) If @error Then Return SetError(@error, @extended, False) Return SetExtended($aResult[5], $aResult[0] <> 0) EndFunc ;==>_Console_FillOutputCharacter Func _Console_GetScreenBufferSize($hConsoleOutput = -1) Local $tConsoleScreenBufferInfo, $aRet[2] $tConsoleScreenBufferInfo = _Console_GetScreenBufferInfo($hConsoleOutput) If @error Then Return SetError(@error, @extended, 0) $aRet[0] = DllStructGetData($tConsoleScreenBufferInfo, "SizeX") $aRet[1] = DllStructGetData($tConsoleScreenBufferInfo, "SizeY") Return $aRet EndFunc ;==>_Console_GetScreenBufferSize Func _Console_GetScreenBufferInfo($hConsoleOutput = -1, $hDll = -1) Local $tConsoleScreenBufferInfo, $aResult Local Const $tagCONSOLE_SCREEN_BUFFER_INFO = "SHORT SizeX; SHORT SizeY; SHORT CursorPositionX;" & _ "SHORT CursorPositionY; SHORT Attributes; SHORT Left; SHORT Top; SHORT Right; SHORT Bottom;" & _ "SHORT MaximumWindowSizeX; SHORT MaximumWindowSizeY" If $hConsoleOutput = -1 Then $hConsoleOutput = _Console_GetStdHandle() $tConsoleScreenBufferInfo = DllStructCreate($tagCONSOLE_SCREEN_BUFFER_INFO) $aResult = DllCall("kernel32.dll", "bool", "GetConsoleScreenBufferInfo", _ "handle", $hConsoleOutput, _ "ptr", DllStructGetPtr($tConsoleScreenBufferInfo)) If @error Or (Not $aResult[0]) Then Return SetError(@error, @extended, 0) Return $tConsoleScreenBufferInfo EndFunc ;==>_Console_GetScreenBufferInfo Func _Console_GetStdHandle($nStdHandle = -11) Local $aResult $aResult = DllCall("kernel32.dll", "handle", "GetStdHandle", _ "dword", $nStdHandle) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc ;==>_Console_GetStdHandle Mostly lifted straight from my console UDF, I think most of those functions will now be available in WinAPIEx so will actually be standard AutoIt functions soon. Basically you fill the console with spaces and move the cursor to square one. Because it is incomprehensible to me. Thank you for your help. Link to comment Share on other sites More sharing options...
nazirm Posted September 25, 2013 Share Posted September 25, 2013 I get the following error when I use zip.au3 and console.au3 together. To simulate this error please create a new script in SciTE script editor and include zip.au3 and console.au3 and then run it. You will get two pop up messages. Here are the error messages: First Popup message: AutoIt Error: Line 456 (File "C:Program Files (z86)|AutoIt3Includezip.au3:): $ZipFile=#ZipSplit[2] $ZipFile=^Error Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded. Second popup message: Line 455 (File "C:Program Files (z86)|AutoIt3IncludeConsole.au3:): If $_Amount_Startup_COnsole Then If^Error Error: Variable used without being declared. Link to comment Share on other sites More sharing options...
LarsJ Posted September 25, 2013 Share Posted September 25, 2013 (edited) nazirm, The problem is that both scripts wants to use $CmdLine. Comment out line 12 - 14 in Zip.au3 to get rid of the error.The only UDFs you can expect will work together without small problems are the UDFs that belong to the official installation. Edited September 25, 2013 by LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 29, 2013 Share Posted December 29, 2013 Sry for gravedigging, but how about adding a Consoleclear command? Or how can I clear the console using ur udf? Link to comment Share on other sites More sharing options...
Shaggi Posted March 29, 2014 Author Share Posted March 29, 2014 Sry for gravedigging, but how about adding a Consoleclear command? Or how can I clear the console using ur udf? Sorry i haven't been around. Either use system("cls") or write a wrapper around FillConsoleOutputCharacterW, as brewman said. Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
Biatu Posted April 5, 2014 Share Posted April 5, 2014 Sry for gravedigging, but how about adding a Consoleclear command? Or how can I clear the console using ur udf? There is a _WinAPI_ClearConsole.... What is what? What is what. Link to comment Share on other sites More sharing options...
FaridAgl Posted April 6, 2014 Share Posted April 6, 2014 To avoid using global variables, you can declare variables like $__Console__hCtrlHandler (Which is used only in 1 function and its value needs to be available also in next calls), you can declare them inside the related functions as Local Static. Func RegisterConsoleEvent($fFunc, $dwSig = $sigCtrlClose, $bRegisterExit = True) Local Static $__Console__hCtrlHandler = 0 . . . Nice UDF, thanks, http://faridaghili.ir Link to comment Share on other sites More sharing options...
lsakizada Posted April 9, 2014 Share Posted April 9, 2014 (edited) What is the console's GUI handle that I can interact with it? For example,the use of AdlibRegister inside a script that based on the Console.au3 is not working. I looked at the code and saw that the console is using the function __Console__CreateConsole() but how to get the handle that can be used in function such as "_Timer_SetTimer($Form1, 1000)" where $Form1 is a windows handle. EDIT: Maybe its not working because I am running it on WIN7 64 Bit? Thanks Edited April 9, 2014 by lsakizada Be Green Now or Never (BGNN)! Link to comment Share on other sites More sharing options...
Mat Posted April 9, 2014 Share Posted April 9, 2014 There is a _Console_GetWindow function, though I'm not sure you'll be able to use it for that. (as always, my console functions can be found here: https://github.com/MattDiesel/au3-console) The solution may be to use the autoit hidden window. Look in the helpfile at AutoItWinSetTitle, what you have to do is set the title to something unique, then get the handle using WinGetHandle. If that doesn't work either than you'll have to make your own hidden window. AutoIt Project Listing Link to comment Share on other sites More sharing options...
lsakizada Posted April 9, 2014 Share Posted April 9, 2014 thanks mat for the advise. I will try ... Be Green Now or Never (BGNN)! Link to comment Share on other sites More sharing options...
Sudhir229 Posted May 6, 2014 Share Posted May 6, 2014 (edited) Hi , I want to print the output of the autoit script on the same CMD(DOS) console. Can I use this UDF do print the output of the result of the script on the same CMD console where I ran the script? Just like "hostname" command print the output on the same CMD window. I can able to print the value in the MSG box but want to print it on the same CMD window. Thanks, Edited May 6, 2014 by Sudhir229 Link to comment Share on other sites More sharing options...
GraaF1337 Posted August 6, 2014 Share Posted August 6, 2014 Is there a way to get a color like yellow into it? Because i use Green, Red, and Gray ALOT, but the Blue one is very hard to see without a background, and i think the way backgrounds are made in CMD looks weird Link to comment Share on other sites More sharing options...
de1m Posted September 12, 2014 Share Posted September 12, 2014 can someone tell me, how can I change Cin to input a password? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now