Check for pressed key in console application

  • Thread starter Thread starter Marco Singer
  • Start date Start date
M

Marco Singer

Hi all,

is it possible to check if a key was pressed in a VB.NET console
application?

I have a loop which runs a long time and want it to exit if a key was
pressed. What I NOT want is to wait until a key is pressed...

Thanks

Marco
 
Marco,

Can you try if something silly as this fits your problem as sample?

I hope this helps?

Cor
\\\
Sub Main()
Dim myProcess As New Process
myProcess.StartInfo.FileName = "Sort.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.RedirectStandardInput = True
myProcess.Start()
Dim FT As System.Threading.Thread
FT = New System.Threading.Thread(AddressOf DoSomething)
FT.Start()
Dim inputText As String
Dim numLines As Integer = 0
Do
inputText = Console.ReadLine()
Loop While inputText.ToLower <> "stop"
FT.Abort()
myProcess.Close()
End Sub
Private Sub DoSomething()
Dim A As Integer = 1
Do
A = 1 * A
Loop
End Sub
///
 
* "Marco Singer said:
I have a loop which runs a long time and want it to exit if a key was
pressed. What I NOT want is to wait until a key is pressed...

That's not supported by the current version of the 'Console' class.
 
Herfried,
That's not supported by the current version of the 'Console' class.


Have a look at my sample provided in this thread.

Something wrong with it, it was just an idea?.

Cor
 
* "Cor Ligthert said:
Have a look at my sample provided in this thread.

Something wrong with it, it was just an idea?.

'ReadLine' will return only if the return key is pressed...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top