472,805 Members | 1,135 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How can I "peek" at the keyboard without suspending?

Something like getchar() doesn't work, since it "waits" for input.
#include <stdio.h>
while (1)
{
if (getchar()) /* break if any key is pressed */
{
break;
}

/* lot's of other code goes here */
}
Nov 13 '05 #1
11 4830
In article <f5**************************@posting.google.com >, Jeffrey Hiess wrote:
Something like getchar() doesn't work, since it "waits" for input.

Read this FAQ:

http://www.eskimo.com/~scs/C-faq/q19.1.html
--
Andreas Kähäri
Nov 13 '05 #2
Andreas Kahari <ak*******@freeshell.org> wrote:
In article <f5**************************@posting.google.com >, Jeffrey Hiess wrote:
Something like getchar() doesn't work, since it "waits" for input.

Read this FAQ:

http://www.eskimo.com/~scs/C-faq/q19.1.html


To OP: in future please cross-post your message instead of
multi-posting. Your question has already been answered in
alt.comp.lang.learn.c-c++. Thank you.

Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #3
In <f5**************************@posting.google.com > je***********@honeywell.com (Jeffrey Hiess) writes:
Something like getchar() doesn't work, since it "waits" for input.


Ever considered reading the FAQ *before* posting?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #4
Da*****@cern.ch (Dan Pop) wrote in message news:<bq**********@sunnews.cern.ch>...
In <f5**************************@posting.google.com > je***********@honeywell.com (Jeffrey Hiess) writes:
Something like getchar() doesn't work, since it "waits" for input.


Ever considered reading the FAQ *before* posting?

Dan


Did I miss something? Which FAQ? Please expound. I'm posting from
Google Groups.

On the topic of the original post, I am hesitant to write platform
specific code to avoid suspending. Instead, I was pondering the idea
of forking a sub process which would call getchar() (and suspend) and
then main process could monitor the sub process for a signal to take
action. My multi-threading coding skills are a bit rusty, but it seems
like this would work.
Nov 13 '05 #5
je***********@honeywell.com (Jeffrey Hiess) writes:
Da*****@cern.ch (Dan Pop) wrote in message
news:<bq**********@sunnews.cern.ch>...
In <f5**************************@posting.google.com >
je***********@honeywell.com (Jeffrey Hiess) writes:
Something like getchar() doesn't work, since it "waits" for input.


Ever considered reading the FAQ *before* posting?

Dan


Did I miss something? Which FAQ? Please expound. I'm posting from
Google Groups.

On the topic of the original post, I am hesitant to write platform
specific code to avoid suspending. Instead, I was pondering the idea
of forking a sub process which would call getchar() (and suspend) and
then main process could monitor the sub process for a signal to take
action. My multi-threading coding skills are a bit rusty, but it seems
like this would work.


Forking and monitoring other processes are at least as system-specific
as checking for pending keyboard input.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Nov 13 '05 #6
Jeffrey Hiess wrote:
On the topic of the original post, I am hesitant to write platform
specific code to avoid suspending. Instead, I was pondering the idea
of forking a sub process which would call getchar() (and suspend) and
then main process could monitor the sub process for a signal to take
action. My multi-threading coding skills are a bit rusty, but it seems
like this would work.


Jeffrey...

It sounds like news:comp.unix.programmer might be a good place to
ask this question. If you have access to "Advanced Programming in
the UNIX Environment" by Richard Stevens, you might find it
helpful. You might find http://www.iedu.com/mrd/c/getch.c
(written with help from APUE to run under Linux) interesting.

Note that your code will (necesarily) be less portable than a
standard-compliant program that uses getchar() - the price for
being just a bit chummier with the operating system.

--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.

Nov 13 '05 #7
>On the topic of the original post, I am hesitant to write platform
specific code to avoid suspending.
You have no choice. ANSI C does not provide non-blocking I/O.
Instead, I was pondering the idea
of forking ^^^^^^^
PLATFORM-SPECIFICa sub process ^^^^^^^^^^^
PLATFORM-SPECIFICwhich would call getchar() (and suspend) and
then main process could monitor ^^^^^^^
If this is anything but setting up a signal handler, this is PLATFORM-SPECIFICthe sub process ^^^^^^^^^^^
PLATFORM-SPECIFICfor a signal to take ^^^^^^^^^^^^
sending a signal to another process is PLATFORM-SPECIFIC.action. My multi-threading coding skills are a bit rusty, but it seems ^^^^^^^^^^^^^^^
Multi-threading except for the skimpy support for signal handlers in C
is PLATFORM-SPECIFIC.
like this would work.


Gordon L. Burditt
Nov 13 '05 #8
je***********@honeywell.com (Jeffrey Hiess) wrote:
Did I miss something? Which FAQ? Please expound. I'm posting from
Google Groups.


That is frequently an explanation, but never an excuse.

Richard
Nov 13 '05 #9
Jeffrey Hiess <je***********@honeywell.com> spoke thus:
Did I miss something? Which FAQ? Please expound. I'm posting from
Google Groups.


Since no one else seemed to be clear, yes, you did miss something -
the FAQ located at http://www.eskimo.com/~scs/C-faq/top.html.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 13 '05 #10
Christopher Benson-Manica wrote:
Jeffrey Hiess <je***********@honeywell.com> spoke thus:
Did I miss something? Which FAQ? Please expound. I'm posting from
Google Groups.


Since no one else seemed to be clear, yes, you did miss something -
the FAQ located at http://www.eskimo.com/~scs/C-faq/top.html.


There seems to be no downloadable version of the full latest FAQ.

Ian

Nov 13 '05 #11
Ian Bell <ia*@ruffrecordsDOTworldonline.co.uk> wrote:
Christopher Benson-Manica wrote:
Jeffrey Hiess <je***********@honeywell.com> spoke thus:
Did I miss something? Which FAQ? Please expound. I'm posting from
Google Groups.


Since no one else seemed to be clear, yes, you did miss something -
the FAQ located at http://www.eskimo.com/~scs/C-faq/top.html.


There seems to be no downloadable version of the full latest FAQ.


Follow the link on http://www.eskimo.com/~scs/C-faq/top.html to
http://www.eskimo.com/~scs/C-faq/versions.html and from there to
ftp://ftp.eskimo.com/u/s/scs/C-faq/faq.Z.

Or try: http://www.faqs.org/faqs/C-faq/faq/index.html (~280K).

HTH ;)

Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.angelfire.com/ms3/bchambl...me_to_clc.html
clc faq-list : http://www.eskimo.com/~scs/C-faq/top.html
acllc-c++ faq : http://www.contrib.andrew.cmu.edu/~a...acllc-c++.html
Nov 13 '05 #12

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

Similar topics

19
by: les_ander | last post by:
Hi, suppose I am reading lines from a file or stdin. I want to just "peek" in to the next line, and if it starts with a special character I want to break out of a for loop, other wise I want to...
41
by: AngleWyrm | last post by:
I have created a new container class, called the hat. It provides random selection of user objects, both with and without replacement, with non-uniform probabilities. Uniform probabilities are a...
4
by: Tim | last post by:
I have used a graphic 'next record' button on a form. How can I stop it from going past the last existing record? In other words, I don't want it to take the user to a blank record. Thanks Tim
32
by: Next | last post by:
Hi folks, Years ago, it occurred to me that a lot of the trouble of writing web browsers is caused by the upside-down arrangement of things: Javascript code exists inside a document, when...
2
by: Ken Schutte | last post by:
Lets say I want an integer class that lets you attach arbitrary attributes. I can simply do: class foo(int): pass x = foo(5) x.text = "okay" print x, x.text # prints "5 okay" So,...
15
by: waltbrad | last post by:
Hello. I'm studying the book "C++ Primer Plus" by Stephan Prata. In chapter 6 he gives an exercise that reads from a file. The list is thus: 4 Sam Stone 2000 Freida Flass 100500 Tammy...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.