VB.net Console Application Problem

Soldato
Joined
9 Jan 2003
Posts
6,801
Location
Darlington
I am trying to understand how to detect a simple keypress while running a console application under vb.net.

In short I would like a loop to repeat continuously until a key press is detected at which point it would exit the loop.

I have this so far:

Module Module1
Private theKey As ConsoleKeyInfo = New ConsoleKeyInfo

Sub Main()

Do
'theKey = Console.ReadKey(True)
Select Case theKey.Key
Case ConsoleKey.Enter
Exit Do
Case Else
Console.WriteLine("Hello World")
End Select
Loop
End Sub

End Module


...but this requires a key press every iteration which is what I am trying to avoid, however the enter keypress does exit the loop so part of it is work.

Any ideas?

Egon
 
This seems to do exactly the same as what my code above is doing. The loop isn't continuous, I need to press a key to initiate the next iteration. I want the program to loop continuously and stop when I press a key.
 
Back
Top Bottom