Re: Console app, reading lines etc.
- From: "Family Tree Mike" <FamilyTreeMike@xxxxxxxxxxxxxxxx>
- Date: Tue, 3 Mar 2009 19:09:36 -0500
"Paul" <vis@xxxxxxxxxxxxx> wrote in message news:FB6E48D4-5F25-408D-BC67-71D284FC1188@xxxxxxxxxxxxxxxx
Hi,
In a console app, using VB2008, I'm trying to emulate some of the
functionality available in cmd.exe. Specifically, if in cmd.exe, and you type
"cd <TAB>" it toggles between folder names.
I need to read information that the user types, or, alternatively, if user
hits the TAB key, I want to toggle the text displayed between a list of
strings I have ready in the app.
Any idea of an available framework for this sort of thing. I'm struggling
with my code, getting myself confused by readkey and readline, and handling
backspaces etc.
Regards
Paul
I believe the only way to do this is to suppress the keys going to the console when typed, and only utilizing console.write, bypassing console input. The following code shows an example:
Sub Main()
Dim input As String = "ok"
Dim idx As Integer = 0
Dim words As List(Of String) = New List(Of String)
words.Add("Green")
words.Add("Blue")
words.Add("Volvo")
While (input <> String.Empty)
input = String.Empty
Dim key As ConsoleKeyInfo
Dim flag As Boolean = True
Dim justtabbed As Boolean = False
While flag
' suppress key going to console
key = Console.ReadKey(True)
Select Case key.Key
Case ConsoleKey.Enter
flag = False
justtabbed = False
Case ConsoleKey.Tab
If (justtabbed) Then
' erase previous word
For j As Integer = 1 To words(idx).Length
Console.Write(ControlChars.Back)
Console.Write(" ")
Console.Write(ControlChars.Back)
Next
input = input.Substring(0,
input.Length - words(idx).Length)
End If
idx = idx + 1
If (idx = words.Count) Then idx = 0
Console.Write(words(idx))
justtabbed = True
input = input + words(idx)
Case Else
Console.Write(key.KeyChar)
input = input + key.KeyChar
justtabbed = False
End Select
End While
Console.WriteLine()
Console.WriteLine("-> [" & input & "]")
End While
End Sub
Hopefully this helps.
--
Mike
.
- Follow-Ups:
- Re: Console app, reading lines etc.
- From: Paul
- Re: Console app, reading lines etc.
- From: Paul
- Re: Console app, reading lines etc.
- References:
- Console app, reading lines etc.
- From: Paul
- Console app, reading lines etc.
- Prev by Date: Re: question on logging block
- Next by Date: Calling a Windows DLL method (C++) from C#, passing a structure reference.
- Previous by thread: Console app, reading lines etc.
- Next by thread: Re: Console app, reading lines etc.
- Index(es):
Relevant Pages
|