473,396 Members | 1,809 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,396 software developers and data experts.

how to "wait for any key"

What is the most portable way of "waiting for any key", i.e. the user
who runs a program from the console should observe the following:

- the program stops running
- as soon as the user presses any keyboard key (alphanum/Enter), the
program continues.

Thanks a lot,
Alex.
Nov 14 '05 #1
4 7262
Alexander Malkis wrote:
What is the most portable way of "waiting for any key", i.e. the user
who runs a program from the console should observe the following:

- the program stops running
- as soon as the user presses any keyboard key (alphanum/Enter), the
program continues.

Thanks a lot,
Alex.

There is no portable way. The closest you can get is using
gethcar(), but that will only return when the user presses enter, and
other keys pressed will be echoed to the console.

You could possibly use some kind of portable I/O library to achieve
portability across at least some platforms. Or you could do your
project in a language that has such functions standardized,
can't think of any right now.

Tor
Nov 14 '05 #2
Alexander Malkis writes:
What is the most portable way of "waiting for any key", i.e. the user
who runs a program from the console should observe the following:

- the program stops running
- as soon as the user presses any keyboard key (alphanum/Enter), the
program continues.


Isolate the function you need in a function of your own making. Have that
function (kind of an emulator) do whatever is necessary to implement the
logic you need as each new platform comes to light. Do a *usenet* search
for conio and ncurses for a good start on what you need. You will need to
use the pre processor to decide which platform is being compiled for if you
insist on automating the process. I wouldn't automate it unless there was
some cash money involved, that is, I would compile on an ad hoc basis.

Someone may have already done this and you could conceivably make a lucky
hit on Usenet. It is certainly something the world needs.
Nov 14 '05 #3
Alexander Malkis <al*****************@line.cs.uni-sb.de> wrote:
# What is the most portable way of "waiting for any key", i.e. the user
# who runs a program from the console should observe the following:

(1) No portable way.
(2) Confuses the hell out of some people. (Where's the ANY key?)
(3) Doesn't invariably work. SHIFT or CTRL, for example, might not send
any codes to the computer. ESC or CTRL-C can break your program.

Just say "Hit enter (or return)" and use fgets. Clear, simple, direct,
portable, and easy enough for nearly everyone.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
I think that's kinda of personal; I don't think I should answer that.
Nov 14 '05 #4
fgets(...) is a good idea! Thank you.
I was thinking of getch() from ncurses, but it's not standard.

Derk Gwen wrote:
Alexander Malkis <al*****************@line.cs.uni-sb.de> wrote:
# What is the most portable way of "waiting for any key", i.e. the user
# who runs a program from the console should observe the following:

(1) No portable way.
(2) Confuses the hell out of some people. (Where's the ANY key?)
(3) Doesn't invariably work. SHIFT or CTRL, for example, might not send
any codes to the computer. ESC or CTRL-C can break your program.

Just say "Hit enter (or return)" and use fgets. Clear, simple, direct,
portable, and easy enough for nearly everyone.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
I think that's kinda of personal; I don't think I should answer that.

--

Best regards,
Alex.

PS. My real email is formed by deleteing the letter combination
"loeschedies" from the email address given.
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vivien Mallet | last post by:
Hello, I use popen2.Popen4 and I experienced problems with it. Let me show you with an example. The following script is called "lines" (it prints lines of 'X'): ---------------------...
1
by: Alex Li | last post by:
Dear js/xmlhttp experts, I spent hours but could not solve this problem and hope someone could give me a clue: a onclick event will invoke a function to do a few things: 1. make a hidden DIV...
1
by: metsymani | last post by:
In my web application, I have a search screen coded in ASP.Net. The Search process takes lot of time. So, I need to show a wait page informing the user that "Search is in progress. Please wait" along...
2
by: Alexander Malkis | last post by:
What is the most portable way of "waiting for any key", i.e. the user who runs a program from the console should observe the following: - the program stops running - as soon as the user presses...
3
by: John Dalberg | last post by:
Hi I have a form that opens a new window for the results. Because the results might take a few seconds due to server processing, I would like to display a message "please wait" in the new...
1
by: Huey | last post by:
Hi All, I encountered a funny thing, and my code schetch as below: #define READ 0 #define WRITE 1 int byteRead, status, pd; char buff;
3
by: Aaron Queenan | last post by:
I have a form which performs some asynchronous code. I want to display a wait cursor when it starts, and hide the wait cursor when it has completed. This part works fairly well, using: ...
1
by: VMI | last post by:
How can I add a small "Please wait..." form to a child form so that when I minimize the child form, the "Please Wait..." form will also disappear? This form will be displayed when the child form is...
5
by: Jeremy | last post by:
Hi all, I have database actions that will potentially take several seconds to complete. My normal page uses AJAX so keeping the user informed of what is happening is not a problem. ...
1
by: =?Utf-8?B?Sm9obiBXYWxrZXI=?= | last post by:
Hi, I have a webpage designed with asp.net 2.0. Is there a way to display a "please wait" message to the screen horizontally centered and veritcally 20px from the VISIBLE top of the page,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...

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.