C question

C question

Post by Andrew Mye » Fri, 08 Sep 1995 04:00:00



: I'm working on a project that requires responses to single key-presses,
: and obviously getchar() alone will not do it.  How can I get my program to
: recognize a key without pressing return after it (like getch() in DOS)??

: Thanks!

: Larry

_Expert C Programming_ by Peter van der Linden has a few methods for
doing this.  The simplest one he mentions is to call

system("stty raw");

before the keyboard input, and

system("stty cooked");

after.  Then, you can just use getchar() to fetch one character at a
time.

Andy

 
 
 

C question

Post by Gary War » Fri, 08 Sep 1995 04:00:00



>I'm working on a project that requires responses to single key-presses,
>and obviously getchar() alone will not do it.  How can I get my program to
>recognize a key without pressing return after it (like getch() in DOS)??

>Thanks!

>Larry

The only way I know to do this is to use curses.  The curses library, of
course, does much more than this, but you don't have to use it.  I have
used it in the past for exactly this reason and about the only problem I ran
into was that it seemed to insist on clearing the screen when you started it
up.  See the man page for curses.
--
+------------------------------------------------------------------+
|                        | To see a world in a grain of sand,      |
| Gary Ward              | And a heaven in a wild flower,          |

|                        | And eternity in an hour.                |
|                        |                      -- William Blake   |
+------------------------------------------------------------------+

 
 
 

C question

Post by Larry Battra » Fri, 08 Sep 1995 04:00:00


I'm working on a project that requires responses to single key-presses,
and obviously getchar() alone will not do it.  How can I get my program to
recognize a key without pressing return after it (like getch() in DOS)??

Thanks!

Larry

 
 
 

C question

Post by Robert L » Tue, 12 Sep 1995 04:00:00


: I'm working on a project that requires responses to single key-presses,
: and obviously getchar() alone will not do it.  How can I get my program to
: recognize a key without pressing return after it (like getch() in DOS)??

: Thanks!

: Larry

The best solution I have seen is is a section on terminal i/o by Marc Rochkin
in his book "Advanced Unix Programming."  It not only covers setting the
keyboard in raw mode but also goes into having virtual keys where the multiple
characters that are returned for a number of the keys are evaluated and
return a single code to the calling routine.  This would be more like getch()
in dos.


 
 
 

C question

Post by Robert H. Meg » Tue, 12 Sep 1995 04:00:00


: I'm working on a project that requires responses to single key-presses,
: and obviously getchar() alone will not do it.  How can I get my program to
: recognize a key without pressing return after it (like getch() in DOS)??

 Is kbhit() still used?  I don't know if it's ansi compliant or not but
it does what you want.

--
====================================================================
Breathe in and breathe out,      |          Robert Megee

====================================================================

 
 
 

C question

Post by SteveB I » Wed, 13 Sep 1995 04:00:00


kbhit isn't ANSI or UNIX compliant
(works great in dos and windows, though)

I vote for curses.

Check out _Advanced_C_Programming_for_Displays
by Marc Rochkind for platform portale ways to do this.

 
 
 

1. Mini-Linux Distribution Questions + General Questions + UMSDOS Questions

Basically I have recently installed the Mini-Linux distribution (from
sunsite.unc.edu) on my box  (486 66, 12Mb, Limited HDD space), and it
works and installs fine, runs fine.... Great I thought, lets install
on several other PC's - Install on another 486d266 - won't even start
- LOADLIN doesn't even begin decompressing the kernal......
Then try a 486dx4100, this time it decompresses kernal and starts
linux startup, and comes up with a HDD sector size too big (its a
544Mb drive) and says "Giving up"..... Linux doesn't start at all.
Anyone else got an experience with this (the mini-linux distribution
is 1.0.9 kernal I think)

Next On the PC that mini-linux runs on, X won't start - cannot start
my graphics card (its an Advance Logic card, Vesa compatible).  Anyone
know how to fix this?

I run mini-linux for several reasons, the main one being the lack of
HDD space (I have 20Mb free without mini-linux, 0.5Mb with), howver I
have heard that the latest distributions include UMSDOS, so now onto
the UMSDOS questions:

Which kernal works best with UMSDOS, and will fit in 20Mb, with the
majority of data residing on CD?

Do the latest linux kernals support a SB16 and panasonic double speed
CD?  Also are NEC drives supported (a mate has one of these)

Basically I cannot delete my  DOS partition, as my family cannot use
linux to save their lives, and love MS word, so I need UMSDOS, so both
can happily reside on one partition (I don't want to partition)

Also does UMSDOS have any problem booting off a d: drive (I am
installing another 100Mb drive to try to alleviate the space problem)

Right thats it......
Thanks for your help and I apologize for the bad spelling in some
places (my software don't spell check).

IMPORTANT:  My news feed is knackered, so can replyies be by mail as
well as news please?

Dan (Linux newbie)

2. xserver failure

3. Questions, questions questions

4. CVS and Windows

5. 3 issues --- 1-Gnome Question, 2-CDRom Detect Question, 3-IMLIB Question

6. PPP-2.2.0f compile under 1.2.3 ?

7. Questions Questions Questions ???

8. Linux in CD

9. Questions, Questions, and more Questions..

10. 3 issues --- 1-Gnome Question, 2-CDRom Detect Question, 3-IMLIB Question

11. Newbie Questions (ICEWM Background, ppp question, mem > 64mb)

12. sar Question (probably a newbie question)

13. A followup question to "A C question (about strlen)"