read the keyboard inputs directly

chandimal

New member
Joined
Oct 14, 2008
Messages
1
Programming Experience
Beginner
I want to read the keyboard input directly to a text file not to textbox as default. Can any one help me on this?
 
Last edited by a moderator:
You can handle KeyPress events and write the Char to a text file no problem, but what kind of UI do you propose for this?
This is in the Console subforum... so I would assume the console.

But if this is the console you can't use KeyPress events (Right?)

So you would have to have a loop of ReadKey until a certain key is pressed.
For example:

VB.NET:
Sub Main()
 Dim fWriter As New IO.StreamWriter(New IO.FileStream("C:\file.txt"))
 Dim k as ConsoleKey
 Dim ContinueLoop As Boolean = True
 While ContinueLoop = True
  k = Console.ReadKey()
  If (k = ConsoleKey.Escape) Then 
   ContinueLoop = False
  Else
   fWriter.Write(k.ToString())
   fWriter.Flush()
  End If
 End While
 fWriter.Close()
End Sub

However this will extensively use the hard drive... which is not recommended for performance reasons.

Perhaps you could tell us why it is you are wanting to do this, and perhaps we could suggest a better way to do this.
 
Last edited:
This is in the Console subforum... so I would assume the console.
Rather a good point. I probably had threads from multiple forums open and neglected to notice that. I should be more observant.
 
Back
Top