By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

Check for pressed key in console application

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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
///

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

Nov 21 '05 #2

P: n/a
* "Marco Singer" <ms*****@konplan.com> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

P: n/a
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

Nov 21 '05 #4

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
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?.


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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5

P: n/a
You are right, I missed something found it a nice solution however.

brrrrrrrrr

:-)

Cor
Nov 21 '05 #6

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
You are right, I missed something found it a nice solution however.


I think it's a nice "solution" too ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.