Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect keypress in console?????

Status
Not open for further replies.

Oxymoron

Technical User
Dec 17, 2000
168
0
0
GB
Hello, I'm a bit of a C newbie, and was wondering how I would go about detecting when a key has been pressed in a C program without the user having to signal the end of the input with a linefeed.

(I want to be able to store users' past input, and when they press the UP arrow, their last command appears - like a shell)

I think it might involve signals but am not very expreienced in them.

Any and all suggestions would be very helpful!
thankyou all.

Oxy

we are all of us living in the gutter.
But some of us are looking at the stars.
 
Darwin on Mac OS X, but i want to the program to be compatible with all ANSI C compilers, and ideally work on Free BSD unix.

we are all of us living in the gutter.
But some of us are looking at the stars.
 
This is actually an OS specific feature. There isn't a generic method of doing this.

Having said that, I haven't worked on BSD for a long time (since Sun went to System V). I know you have to mess about with the ioctl calls. Try searching the net for ioctl and keyboard.

On other systems (mainly the PC based ones), they have calls like kbhit or _kbhit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top