473,383 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 6257
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Brian | last post by:
Inside a loop, I need to passively check to see if a key is pressed or not without pausing like raw_input does. Some pseudocode: While true: If a key is pressed which key is pressed do...
7
by: Jared Evans | last post by:
I developed a console application that will continually check a message queue to watch for any incoming data that needs to be inserted into MS SQL database. What would be a low-cost method I...
0
by: Marco Singer | last post by:
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...
3
by: Just Me | last post by:
I need to set the mouse cursor to wait and also check to see if Esc has been pressed. To see if Esc has been pressed I do Application.DoEvents before I check a variable that gets set in...
4
by: Andrés G. Aragoneses [ knocte ] | last post by:
Hello. I am trying to catch the ALT key (but not as a modifier, but as a single key clicked) on a Console application, but neither Read(), ReadLine() nor ReadKey() catch it, how can I do it using...
6
by: Tarun | last post by:
Hi coders, How can check the total RAM size and the number of RAM modules and their respective sizes using C#? Regards, Tarun
1
by: VikTehOne | last post by:
Is there a way to make thins happen when keys are pressed in a console application... like have a little smily move around the screen with the arrows or with wasd? edit: btw I'm using visual c++ 6
7
by: hlubenow | last post by:
Hello, I'd like to check, if a single key is pressed on a Linux xterm. This code waits for a key to be pressed and returns the character: -------------------------------------------- ...
19
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.