469,267 Members | 971 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

Check for pressed key in console application

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
6 6133
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
* "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
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
* "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
You are right, I missed something found it a nice solution however.

brrrrrrrrr

:-)

Cor
Nov 21 '05 #6
* "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.

Similar topics

7 posts views Thread by Brian | last post: by
4 posts views Thread by Andrés G. Aragoneses [ knocte ] | last post: by
6 posts views Thread by Tarun | last post: by
1 post views Thread by VikTehOne | last post: by
7 posts views Thread by hlubenow | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.