ResNullius Posted January 8, 2010 Share Posted January 8, 2010 The latest Betas no longer support opening a file in RAW mode. One of the neatest uses for this ability is to capture user input from the console in a CUI compiled script, by opening the console in raw mode, as per here: http://www.autoitscript.com/forum/index.php?showtopic=79275&st=0&p=571658&#entry571658 Jon's reason for removal is here: http://www.autoitscript.com/forum/index.php?showtopic=95366&view=findpost&p=761026 and I wouldn't want him adding back in code he wasn't happy with (or writing new code from scratch to support just one specialized feature). The same functionality should be possible with _WinApi_CreateFile() function. I've read the MSDN documentation on the function @ http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspx but I can't seem to get the parameters right... maybe I need _WinApi_ReadFile() too? Looking for some assistance from the DllCall() gurus. And yes, I've read monoceres's tutorial on Dll calls, but that hasn't helped me in this instance. Thanks Link to comment Share on other sites More sharing options...
Mat Posted January 8, 2010 Share Posted January 8, 2010 (edited) I've done it I've been pointing to Valiks example for ages but you never saw it. #AutoIt3Wrapper_Change2CUI=y #include <WinAPI.au3> ConsoleWrite ("text: ") Local $tBuffer = DllStructCreate("char") Local $nRead, $sRet Local $hFile = _WinAPI_CreateFile("CON", 2, 2) While 1 _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead) If DllStructGetData ($tBuffer, 1) = @CR Then ExitLoop $sRet &= DllStructGetData ($tBuffer, 1) WEnd _WinAPI_CloseHandle($hFile) MsgBox(4096, "", $sRet) Dibs making udf Mat Edit: Programmer friendly: #AutoIt3Wrapper_Change2CUI=y #include <WinAPI.au3> ConsoleWrite("text: ") $sText = _ConsoleReadLine() MsgBox(0, "Result", $sText) Func _ConsoleReadLine() If Not @Compiled Then Return SetError(1, 0, 0) ; Not compiled Local $tBuffer = DllStructCreate("char"), $nRead, $sRet = "" Local $hFile = _WinAPI_CreateFile("CON", 2, 2) While 1 _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead) If DllStructGetData($tBuffer, 1) = @CR Then ExitLoop If $nRead > 0 Then $sRet &= DllStructGetData($tBuffer, 1) WEnd _WinAPI_CloseHandle($hFile) Return $sRet EndFunc ;==>_ConsoleReadLine Edited January 8, 2010 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Zedna Posted January 8, 2010 Share Posted January 8, 2010 (edited) Look at my topic with example for using File API functions.This my example is also in Autoit helpfile at _WinAPI_SetFilePointer()http://www.autoitscript.com/forum/index.php?showtopic=76829 Edited January 8, 2010 by Zedna Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
ResNullius Posted January 8, 2010 Author Share Posted January 8, 2010 I've done it I've been pointing to Valiks example for ages but you never saw it. Thank's Mat; that's what I wanted. I did search forums (with built-in and Google) for _WinApi_CreateFile("con" but didn't find any direct results) Do you have a link to Valik's example (I like to keep track of authors and seeds of origin where possible). Also, slight mod of your function to make it "all-in-one", kinda like InputBox(): ;credits to Valik & Mat #AutoIt3Wrapper_Change2CUI=y #include <WinAPI.au3> $sResponse = _ConsoleInput("Please input some text: ") ConsoleWrite("You Entered: " & $sResponse & @CRLF) Func _ConsoleInput($sPrompt) If Not @Compiled Then Return SetError(1, 0, 0) ; Not compiled ConsoleWrite($sPrompt) Local $tBuffer = DllStructCreate("char"), $nRead, $sRet = "" Local $hFile = _WinAPI_CreateFile("CON", 2, 2) While 1 _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead) If DllStructGetData($tBuffer, 1) = @CR Then ExitLoop If $nRead > 0 Then $sRet &= DllStructGetData($tBuffer, 1) WEnd _WinAPI_CloseHandle($hFile) Return $sRet EndFunc mikkokh 1 Link to comment Share on other sites More sharing options...
Mat Posted January 8, 2010 Share Posted January 8, 2010 http://www.autoitscript.com/forum/index.php?showtopic=107752&view=findpost&p=760049 Thats the link to Valiks original post. Interestingly enough I was considering doing exactly the same thing, and calling it _ConsoleQuery... AutoIt Project Listing Link to comment Share on other sites More sharing options...
ResNullius Posted January 8, 2010 Author Share Posted January 8, 2010 I've done it I've been pointing to Valiks example for ages but you never saw it.http://www.autoitscript.com/forum/index.php?showtopic=107752&view=findpost&p=760049Thats the link to Valiks original post.So Valik's original post was on the 5th of January, today's the 8th, and you've been pointing to his example for ages? Link to comment Share on other sites More sharing options...
Valik Posted January 8, 2010 Share Posted January 8, 2010 So Valik's original post was on the 5th of January, today's the 8th, and you've been pointing to his example for ages? He pointed to it hours ago in the Latest Beta thread. That qualifies as "ages" in my book. Link to comment Share on other sites More sharing options...
Horiz Posted November 15, 2010 Share Posted November 15, 2010 Is there anyway to use this method and gather a single keystroke without the user having to hit the enter key. I'm wanting to emulate the functionality of the choice.com program which does not work on a 64bit system. With choice.com you can write to console a message and wait for a single key to be pressed and exit with that key as the error code. On 32 bit systems I'm able to use choice.com in a batch file to get a single keystroke from the user. Has anyone seen an autoit3 script of that nature on this forum? Link to comment Share on other sites More sharing options...
killgore Posted April 9, 2014 Share Posted April 9, 2014 Sorry for reviving so old thread, but does someone know why this piece of code doesn't work properly on Windows 8 / 8.1? You have to press ENTER twice and only second string is returned. The same compiled program run on Windows 7 works great. Link to comment Share on other sites More sharing options...
Mat Posted April 9, 2014 Share Posted April 9, 2014 (edited) You have to turn off the ENABLE_LINE_INPUT in order for the console read functions to return immediately. Example:Â #AutoIt3Wrapper_Change2CUI=n #include <WinAPI.au3> #include "Console.au3" _Console_Alloc() _WinAPI_SetLastError(0) _Console_ReadOutputCharacter(-1, 1, 1, 1) If _WinAPI_GetLastError() = 6 Then Run("""" & @AutoItExe & """ /AutoIt3ExecuteScript """ & @ScriptFullPath & """ " & $CmdLineRaw, @WorkingDir, @SW_SHOW, 0) Exit EndIf _Console_Write("Test: ") $sText = _Console_ReadConsole(-1, False) MsgBox(0, "Result", $sText) Killgore, as mentioned in the pm, the above code will work for you too, just change _Console_ReadConsole(-1, False) to _Console_ReadConsole() to read the whole line. Edit: It seems like this thread is getting hijacked a little. It's about time I just made a thread for console.au3 on it's own. Maybe renaming it to WinAPIConsole.au3 to avoid confusion with this thread. there are still a lot of things I don't understand and need fixing but most of the answers are there now. Edited April 9, 2014 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
newtonspls Posted December 16, 2014 Share Posted December 16, 2014 Hi- In response to Kilgores question about having to enter twice with Windows 8, where do you turn off "ENABLE_LINE_INPUT"? I'm using the Valiks code example to read the input from the console and doing simple validation on the return. expandcollapse popup#AutoIt3Wrapper_Change2CUI=y #include <WinAPI.au3> #include <StringConstants.au3> #include <console.au3> _GetServiceInfoCMD() Func _ConsoleInput($sPrompt) If Not @Compiled Then Return SetError(1, 0, 0) ; Not compiled ConsoleWrite($sPrompt) Local $tBuffer = DllStructCreate("char"), $nRead, $sRet = "" Local $hFile = _WinAPI_CreateFile("CON", 2, 2) While 1 _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead) If DllStructGetData($tBuffer, 1) = @CR Then ExitLoop If $nRead > 0 Then $sRet &= DllStructGetData($tBuffer, 1) WEnd _WinAPI_CloseHandle($hFile) Return $sRet EndFunc Func _GetServiceInfoCMD() Local $sCustomerID = _ConsoleInput("Please enter your Customer ID: ") Local $iDcount = StringLen($sCustomerID) Local $iIsNumber = StringIsDigit($sCustomerID) While $iIsNumber <> 1 ConsoleWrite( $sCustomerID & " is not a valid entry, numbers are only allowed." & @CRLF) $sCustomerID = _ConsoleInput("Please enter again: ") $iIsNumber = StringIsDigit($sCustomerID) ConsoleWrite("IsNumber: " & $iIsNumber & @CRLF) WEnd While $iDcount <> 7 ConsoleWrite("Incorrect amount of numbers, only 7 are allowed." & @CRLF) $sCustomerID = _ConsoleInput("Please enter again: ") $iDcount = StringLen($sCustomerID) ConsoleWrite("Count: " & $iDcount & @CRLF) WEnd EndFunc Melba23 1 Link to comment Share on other sites More sharing options...
carstengiese Posted July 18, 2019 Share Posted July 18, 2019 Is there any way to prompt for a password with this code WITHOUT showing the password, but something like "******" during input? Link to comment Share on other sites More sharing options...
jchd Posted July 18, 2019 Share Posted July 18, 2019 InputBox() This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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