I have a console application that I want to continue to run until I press a
key.
How can I get a keypress without stopping execution?
Thanks. 5 6628
Console.Read() will wait until a key is pressed. You can get the input and test to see if the character is Q and quit or read another character.
But that is the point, I don't want the application to stop. I want the app
(in a loop) to keep running UNTIL I press 'Q'.
"Tim Begin" <an*******@disc ussions.microso ft.com> wrote in message
news:E3******** *************** ***********@mic rosoft.com... Console.Read() will wait until a key is pressed. You can get the input
and test to see if the character is Q and quit or read another character.
Hmm, you could start a new thread that executes your buisness logic, and
have your main thread wait for input, when the input comes you could kill
the buisness thread, is that what you wanted?
"WildHare" <ki******@siva. com> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl... But that is the point, I don't want the application to stop. I want the
app (in a loop) to keep running UNTIL I press 'Q'.
"Tim Begin" <an*******@disc ussions.microso ft.com> wrote in message news:E3******** *************** ***********@mic rosoft.com... Console.Read() will wait until a key is pressed. You can get the input and test to see if the character is Q and quit or read another character.
WildHare wrote: But that is the point, I don't want the application to stop. I want the app (in a loop) to keep running UNTIL I press 'Q'.
"Tim Begin" <an*******@disc ussions.microso ft.com> wrote in message news:E3******** *************** ***********@mic rosoft.com...
Console.Read( ) will wait until a key is pressed. You can get the input
and test to see if the character is Q and quit or read another character.
This isn't supported in the 1.x Framework Console class. I believe that
it is supported in the upcoming 2.0 Framework (I know - that doesn't
help you today...).
The solution that others have mentioned working involves using P/Invoke
to the Win32 Console APIs. I have no sample for you, as I haven't
needed to do this, but I'm sure that a quick Google would net some good
results.
Or just write the P/Invoke wrappers yourself, it can't be all that complex.
--
mikeb
My head is spinning with all the paths of execution (the business logic
launches all finds of threads as part of its behavior), but I will find a
way to document that.
The only remaining issue is that I have to press <enter> for the Q to be
read. I guess, unless I want to make API calls I am stuck with that ...
right?
"Carlson Quick" <ca******@exten dedsystems.com> wrote in message
news:Ov******** ******@TK2MSFTN GP10.phx.gbl... Hmm, you could start a new thread that executes your buisness logic, and have your main thread wait for input, when the input comes you could kill the buisness thread, is that what you wanted?
"WildHare" <ki******@siva. com> wrote in message news:eB******** ******@TK2MSFTN GP11.phx.gbl... But that is the point, I don't want the application to stop. I want the app (in a loop) to keep running UNTIL I press 'Q'.
"Tim Begin" <an*******@disc ussions.microso ft.com> wrote in message news:E3******** *************** ***********@mic rosoft.com... Console.Read() will wait until a key is pressed. You can get the
input and test to see if the character is Q and quit or read another
character.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul Johnston |
last post by:
I'm using VB.Net. I've tried using Console.Read() but it requires a
line-terminator before it finishes (doesn't that mean it's functionally
equivalent to ReadLine() -- why have it then?). I've tried
Console.In.ReadBlock(), too, with no success.
So, along these lines, how would I implement, simply, a "Press Any Key to
Continue" routine or, more complex, a text menu in a Console app to get a
single character?
i.e.
|
by: Oz |
last post by:
This is long. Bear with me, as I will really go through all the convoluted
stuff that shows there is a problem with streams (at least when used to
redirect stdout).
The basic idea is that my application (VB.NET) will start a process,
redirect its stdout and capture that process' output, displaying it in a
window.
I've written a component for this, and a test application for the component.
It allows me to specify a command to execute,...
|
by: Johan Svedberg |
last post by:
Hi!
I read somewhere that it is impossible to write a program in ANSI-C
which only reads one char from the keyboard without having to press
Enter (i.e. -questions). Is this true?
--
Johan Svedberg, johan@svedberg.pp.se, http://johan.svedberg.pp.se/
|
by: Bob Altman |
last post by:
Hi all,
I have an unmanaged console app written in C++. I can't figure out how to
get C++ to do the standard issue "press any key to continue" thing:
cout << "Press any key to continue: ";
cin >> <your code goes here>;
TIA,
|
by: Andrzej J. Turowicz |
last post by:
I create new WebSite named UseWebPart ( sample from Ms Press Book)
next steps:
Add WebPartManagerIO , WebPartZone, EditorZone & CatalogZone, etc etc etc
if i am running this sample under VisualStudio 2005 IDE all modes ( Browse,
Design, Edit, Catalog )
are operational.
Next step, configure WebSita (Users from Lan, anonymous)
| |
by: Susan Rice |
last post by:
I'm running a simple win32 console application and I want to impliment
a "Press any key to continue", so I print that prompt, and then
what's the easiest way to impliment reading any key? Do I use
'getchar', or 'gets', or some get function? or 'cin', or what's
an easy way?
What I want is the program to pause before exiting so the user
can read whatever messages there are before the console window
disappears.
|
by: mzdude |
last post by:
I've just started playing with Python. Installed 2.5 on Windows XP
system. I'm working through some of the examples in Programming Python
3ed by Mark Lutz. Given the following example when the Quit All button
action is assigned to root.quit the windows aren't dismissed or
destroyed. The application appears to terminate, but the windows
remain. When the action is assigned to root.destroy, the windows are
closed. Questions:
1) Which way is...
|
by: Dilip |
last post by:
Hi All
I have a server based C# console application. This application must
hide its console window when its launched out on the field. So I
dutifully P/Invoke'd FindWindow/ShowWindow combination to hide the
console window at launch time.
The application (for legacy reasons) hangs around by waiting on an old-
fashioned Console.ReadLine() statement.
|
by: Andy |
last post by:
Just noticed something interesting in the above. If you have your program
file set to "Compact on Close" in access 2007 (which is desirable when you
have a larger program that frequently needs compacting), if you use the
following code on an "Exit Application" type button, the compacting on close
won't fire:
Application.Quit acQuitSaveNone
however, if you use:
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |