473,326 Members | 2,133 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,326 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 7242
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.