473,573 Members | 2,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6271
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.Start Info.FileName = "Sort.exe"
myProcess.Start Info.UseShellEx ecute = False
myProcess.Start Info.RedirectSt andardInput = True
myProcess.Start ()
Dim FT As System.Threadin g.Thread
FT = New System.Threadin g.Thread(Addres sOf DoSomething)
FT.Start()
Dim inputText As String
Dim numLines As Integer = 0
Do
inputText = Console.ReadLin e()
Loop While inputText.ToLow er <> "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*****@konpla n.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**********@p lanet.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**********@p lanet.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
3697
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 other stuff inside loop
7
3420
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 could use inside this console application to make sure the MS SQL database is operational before I perform the insert?
0
1087
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 until a key is pressed... Thanks
3
1177
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 KeyboardPress if Esc is pressed. According to the Doc calling Application.DoEvents will reset the cursor. Do I have to set the cursor each time I do...
4
7932
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 the System.Console class? Thanks in advance. Regards. Andrés
6
18265
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
3808
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
5226
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: -------------------------------------------- #!/usr/bin/env python import sys
19
107898
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 sure that the user only submits a number to your .NET web application and also demonstrate how to add JavaScript to your ASPX pages. Upon popular...
1
7760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8049
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6392
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5284
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3724
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2185
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.