Detecting A Keypress 
Author Message
 Detecting A Keypress

I have been using getc(stdin) to input characters from the keyboard, but
this doesn't return until the user hits the enter key. Is there a way to
wait for a keypress (and know which key was pressed) and immediately respond
without the user having to hit enter? I am using gcc for Linux, so I can't
use <conio.h>


Sun, 07 Sep 2003 04:54:05 GMT  
 Detecting A Keypress

Quote:
> I have been using getc(stdin) to input characters from the keyboard, but
> this doesn't return until the user hits the enter key. Is there a way to
> wait for a keypress (and know which key was pressed) and immediately respond
> without the user having to hit enter? I am using gcc for Linux, so I can't
> use <conio.h>

There is no way to do it in standard C. For a Linux-specific answer, ask
in comp.unix.programmer or a Linux-specific newsgroup.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/

"That's no raisin - it's an ALIEN!"
   - Tourist in MTV's Oddities



Sun, 07 Sep 2003 05:12:07 GMT  
 Detecting A Keypress
: I have been using getc(stdin) to input characters from the keyboard, but
: this doesn't return until the user hits the enter key. Is there a way to
: wait for a keypress (and know which key was pressed) and immediately respond
: without the user having to hit enter? I am using gcc for Linux, so I can't
: use <conio.h>

See the comp.lang.c FAQ question 19.1.

Paul

--
Paul D. Boyle

North Carolina State University
http://laue.chem.ncsu.edu/web/xray.welcome.html



Sun, 07 Sep 2003 05:15:41 GMT  
 Detecting A Keypress

Quote:

> \--------------------------- Finland rules! ------------/

Sorry, for c.l.c. compatibility, and also for aesthetic reasons, you
should really change this to:

/*---------------------------- Finland rules! -----------*/

By the way: I sincerely hope Finland rules over Finland, but as far as
I'm concerned Finnish rules stop at the border :)

willem



Sun, 07 Sep 2003 05:44:20 GMT  
 Detecting A Keypress

Quote:

> See the comp.lang.c FAQ question 19.1.

Oh, cool, everybody knows, where to read this FAQ. If you have the answer,
please tell it. No references, please.

--
live long and prosper



Sun, 07 Sep 2003 06:11:17 GMT  
 Detecting A Keypress

Quote:


> > See the comp.lang.c FAQ question 19.1.

> Oh, cool, everybody knows, where to read this FAQ. If you have
> the answer, please tell it. No references, please.

Google has the comp.lang.c FAQ as the top answer to a search for
"comp.lang.c FAQ".  Gee, that was *hard*.


Sun, 07 Sep 2003 06:28:10 GMT  
 Detecting A Keypress

Quote:


> > See the comp.lang.c FAQ question 19.1.

> Oh, cool, everybody knows, where to read this FAQ. If you have the answer,
> please tell it. No references, please.

Anyone who is at least vaguely conscious knows where to read this FAQ.
1) It is frequently posted here, so anyone who lurked here before
   positing, which is normal and expected behaviour, knows where it is.
2) The information in news.announce.newuser which should be scanned
   before ever posting to any newsgroup tells how to find FAQs.
3) Most search engines provide easy ways to find FAQs and many browsers
   have such facilities builtin.
4) Many posters include a pointer to the FAQ in their .sigs.  Anyone who
   lurked before posting would know where the FAQ is.
5) I often post the following text.  Anyone who lurked before posting
   would have seen it (BTW corrections and additions are welcome):

    /* Important: This is NOT a flame.  The information
     * below is intended to be useful.
     */

[paragraph From groups.google.com/googlegroups/basics.html]

      "Avoid getting flamed

      "It turns out there is such a thing as a stupid question. It's
      the one that gets asked right after someone answered it for the
      100th time in a newsgroup discussion. Most discussion forums
      have a Frequently Asked Questions (FAQ) section where commonly
      asked questions are posted and answered. You'll likely want to
      read this first upon entering a new group, to ensure your
      question isn't treated like spam (junk mail).  Spammers
      frequently receive flame mail (heated retorts of a personally
      demeaning nature) directing them to please read the FAQ. One way
      to find the FAQ, is to enter "faq" and the name of the
      discussion forum in search box.  You should get back a list of
      results containing the FAQ if one exists."

[locations of some FAQs]

General FAQ sites for comp.lang.* newsgroups
     ftp://rtfm.mit.edu/pub/usenet-by-hierarchy/comp/lang/
     http://www.faqs.org/faqs/by-newsgroup/comp/

comp.lang.c, comp.lang.c.moderated, and comp.std.c FAQ

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

Welcome to comp.lang.c


     http://www.sin.khk.be/~emulov/c.l.c/welcome_to_clc.htm

Jack Klein's C and C++ Pages

     http://home.att.net/~jackklein/c/c_main.html
     (of special inerest:
        http://home.att.net/~jackklein/ctips01.html#homework)

Greg Comeau's C and C++ Pages

     http://www.comeaucomputing.com/techtalk/

alt.comp.lang.learn.c-c++ FAQ
(new site)

     http://snurse-l.org/acllc-c++/faq
(old site)

     http://www.raos.demon.co.uk/acllc-c++/faq.html

comp.lang.C++ FAQ

     FAQ Home Page: http://marshall-cline.home.att.net/cpp-faq-lite/

comp.std.c++ FAQ    



     http://reality.sgi.com/austern_mti/std-c++/faq.html

Welcome to comp.lang.c++

     http://www.slack.net/~shiva/welcome.txt

comp.os.msdos.djgpp FAQ

     http://www.delorie.com/djgpp/v2faq/

de.comp.lang.c FAQ

     http://www2/nformatik/uni-wuerzburg.de/dclc-faq/

[Other newsgroups and hierarchies frequently of interest
    to off-topic posters in comp.lang.c, comp.lang.c++, and
    alt.comp.lang.learn.c-c++]

comp.lang.asm.*
comp.programming   (algorithms)
comp.graphics.*  
comp.os.msdos.*
comp.os.ms-windows.*
comp.os.os2.*
comp.sys.mac.*
comp.unix.*
microsoft.public.vc.*
borland.public.cppbuilder.*
borland.public.cpp.*
gnu.gcc
comp.os.msdos.djgpp (DOS port of gcc)



Sun, 07 Sep 2003 06:30:17 GMT  
 Detecting A Keypress

Quote:

>> See the comp.lang.c FAQ question 19.1.

> Oh, cool, everybody knows, where to read this FAQ. If you have the answer,
> please tell it. No references, please.

What do you mean "no references"? How are we going to tell you where the
FAQ is if you don't want references to it? Anyway, here is a copy of
Richard Heathfield's sig block:

Richard Heathfield
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html

Locating the URL for the C FAQ shouldn't be too hard.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/

"All that flower power is no match for my glower power!"
   - Montgomery Burns



Sun, 07 Sep 2003 06:27:21 GMT  
 Detecting A Keypress

Quote:

>> See the comp.lang.c FAQ question 19.1.

>Oh, cool, everybody knows, where to read this FAQ. If you have the answer,

CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html

Quote:
>please tell it. No references, please.

What do you think a FAQ is made for?

Quote:
>--
>live long and prosper

Q'plah!

--
-hs-    "spaces, not tabs"
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
FAQ de FCLC : http://www.isty-info.uvsq.fr/~rumeau/fclc



Sun, 07 Sep 2003 06:34:43 GMT  
 Detecting A Keypress


Quote:
>I have been using getc(stdin) to input characters from the keyboard, but
>this doesn't return until the user hits the enter key. Is there a way to
>wait for a keypress (and know which key was pressed) and immediately respond
>without the user having to hit enter? I am using gcc for Linux, so I can't
>use <conio.h>

I think you'll find that this is an FAQ.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>



Sun, 07 Sep 2003 06:40:45 GMT  
 Detecting A Keypress
On Tue, 20 Mar 2001 23:11:17 +0100, Christof K?lin

Quote:


>> See the comp.lang.c FAQ question 19.1.

>Oh, cool, everybody knows, where to read this FAQ. If you have the answer,
>please tell it. No references, please.

its in the sig block of about 75% of the regular posters, its posted
here every month or so, and Billy Chambless' weekly "welcome" message
has a pointer too I believe. Did you read that ?

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>



Sun, 07 Sep 2003 07:06:20 GMT  
 Detecting A Keypress
I agree this is a FreqAskedQuestion, however once reading the FAQ I also
believe this is a Frequently Unanswered Question since the FAQ said there is
no "portable" answer.   So..... does anybody "know" how to do this on Linux
using gcc???


Quote:
> I think you'll find that this is an FAQ.

> --
> Mark McIntyre
> CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>



Sun, 07 Sep 2003 08:30:41 GMT  
 Detecting A Keypress

Quote:

>I agree this is a FreqAskedQuestion, however once reading the FAQ I also
>believe this is a Frequently Unanswered Question since the FAQ said there is
>no "portable" answer.   So..... does anybody "know" how to do this on Linux
>using gcc???

Yep.  They live over in comp.unix.programmer .  I'm sure a lot of them
also frequent the various Linux newsgroups.

HTH,HAND
dave

--

C is case-sensitive, rather like English, where you might polish a Polish
hot dog, but would hardly Polish a polish hot dog.
                                             --Chris Torek in comp.lang.c



Sun, 07 Sep 2003 09:01:50 GMT  
 Detecting A Keypress

Quote:
>I agree this is a FreqAskedQuestion, however once reading the FAQ I also
>believe this is a Frequently Unanswered Question since the FAQ said there is
>no "portable" answer.   So..... does anybody "know" how to do this on Linux
>using gcc???

Put the tty driver in raw mode and use getchar().  

Wanna more details?  You know where to find comp.unix.programmer,
right?

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland



Sun, 07 Sep 2003 09:19:57 GMT  
 Detecting A Keypress

Quote:

> I agree this is a FreqAskedQuestion, however once reading the FAQ I also
> believe this is a Frequently Unanswered Question since the FAQ said there is
> no "portable" answer.   So..... does anybody "know" how to do this on Linux
> using gcc???

Yes, and so would you if you read the documentation.  The answer in the
FAQ is all that can be said without turning this newsgroup into a fragmental
usenet sewer,


Sun, 07 Sep 2003 11:20:44 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Detecting a keypress

2. HOW TO: detect a keypress

3. Detecting delete keypress in OnChar

4. Detecting keypress

5. HELP! Keypress detect

6. How To Detect KeyPress.

7. Detecting keypress when the focus is on CButton

8. Detect keypress in dialog-based

9. combobox and keyPress Event

10. Convert keypress to upper case

11. object sender keypress (c# newbie)

12. Tab KeyDown-KeyPress trapping

 

 
Powered by phpBB® Forum Software