PC Review


Reply
Thread Tools Rate Thread

Check for pressed key in console application

 
 
Marco Singer
Guest
Posts: n/a
 
      30th Aug 2004
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


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      30th Aug 2004
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
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      30th Aug 2004
* "Marco Singer" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      30th Aug 2004
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



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      30th Aug 2004
* "Cor Ligthert" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      30th Aug 2004
You are right, I missed something found it a nice solution however.

brrrrrrrrr

:-)

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      30th Aug 2004
* "Cor Ligthert" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if Shift Key Pressed On Start Up nullGumby Microsoft Access Forms 3 2nd Apr 2007 10:11 PM
Check if a normal character was pressed? Pascal Microsoft Dot NET Framework Forms 3 13th Jan 2005 12:45 PM
How check if key pressed in any textbox on winform Woody Splawn Microsoft VB .NET 4 10th Sep 2004 07:57 PM
Check if key was pressed in console application Marco Singer Microsoft VB .NET 0 27th Aug 2004 01:15 PM
How to set a fixed line in a console application liek UNIX console AA Microsoft C# .NET 1 6th Dec 2003 02:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:41 AM.